Part Number Hot Search : 
SCU4C60S JM38510 21002 ISL6610 HN58C 4NK80Z 91SAM 80F6TR
Product Description
Full Text Search
 

To Download PIC16LF872-ISS Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2006 microchip technology inc. ds30221c pic16f872 data sheet 28-pin, 8-bit cmos flash microcontroller with 10-bit a/d
ds30221c-page ii ? 2006 microchip technology inc. information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , micro id , mplab, pic, picmicro, picstart, pro mate, powersmart, rfpic and smartshunt are registered trademarks of micr ochip technology incorporated in the u.s.a. and other countries. amplab, filterlab, migratable memory, mxdev, mxlab, seeval, smartsensor and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, appl ication maestro, codeguard, dspicdem, dspicdem.net, dspicworks, ecan, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, linear active thermistor, mindi, miwi, mpasm, mplib, mplink, pickit, picdem, picdem.net, piclab, pictail, powercal, powerinfo, powermate, powe rtool, real ice, rflab, rfpicdem, select mode, smart serial, smarttel, total endurance, uni/o, wiperlock and zena are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of mi crochip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2006, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona, gresham, oregon and mountain view, california. the company?s quality system processes and procedures are for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2006 microchip technology inc. ds30221c-page 1 pic16f872 high performance risc cpu: ? only 35 single word instructions to learn ? all single cycle instructions except for program branches, which are two-cycle ? operating speed: dc - 20 mhz clock input dc - 200 ns instruction cycle ? 2k x 14 words of flash program memory ? 128 bytes of data memory (ram) ? 64 bytes of eeprom data memory ? pinout compatible to the pic16c72a ? interrupt capability (up to 10 sources) ? eight level deep hardware stack ? direct, indirect and relative addressing modes peripheral features: ? high sink/source current: 25 ma ? timer0: 8-bit timer/counter with 8-bit prescaler ? timer1: 16-bit timer/counter with prescaler, can be incremented during sleep via external crystal/clock ? timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler ? one capture, compare, pwm module - capture is 16-bit, max. resolution is 12.5 ns - compare is 16-bit, max. resolution is 200 ns - pwm max. resolution is 10-bit ? 10-bit, 5-channel analog-to-digital converter (a/d) ? synchronous serial port (ssp) with spi ? (master mode) and i 2 c ? (master/slave) ? brown-out detection circuitry for brown-out reset (bor) cmos technology: ? low power, high speed cmos flash/eeprom technology ? wide operating voltage range: 2.0v to 5.5v ? fully static design ? commercial, industrial and extended temperature ranges ? low power consumption: - < 2 ma typical @ 5v, 4 mhz -20 a typical @ 3v, 32 khz -< 1 a typical standby current pin diagram special microcontroller features: ? power-on reset (por), power-up timer (pwrt) and oscillator start-up timer (ost) ? watchdog timer (wdt) with its own on-chip rc oscillator for reliable operation ? programmable code protection ? power saving sleep mode ? selectable oscillator options ? in-circuit serial programming ? (icsp ? ) via two pins ? single 5v in-circuit serial programming capability ? in-circuit debugging via two pins ? processor read/write access to program memory pic16f872 10 11 2 3 4 5 6 1 8 7 9 12 13 14 15 16 17 18 19 20 23 24 25 26 27 28 22 21 mclr /v pp ra0/an0 ra1/an1 ra2/an2/v ref - ra3/an3/v ref + ra4/t0cki ra5/an4/ss v ss osc1/clkin osc2/clkout rc0/t1oso/t1cki rc1/t1osi/ccp2 rc2/ccp1 rc3/sck/scl rb7/pgd rb6/pgc rb5 rb4 rb3/pgm rb2 rb1 rb0/int v dd v ss rc7/rx/dt rc6/tx/ck rc5/sdo rc4/sdi/sda dip, soic, ssop 28-pin, 8-bit cmos flash microcontroller with 10-bit a/d
pic16f872 ds30221c-page 2 ? 2006 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................ 3 2.0 memory organization......................................................................................................... ......................................................... 7 3.0 data eeprom and flash program memory ........................................................................................ ................................. 23 4.0 i/o ports................................................................................................................... ................................................................. 29 5.0 timer0 module ............................................................................................................... ........................................................... 35 6.0 timer1 module ............................................................................................................... ........................................................... 39 7.0 timer2 module ............................................................................................................... ........................................................... 43 8.0 capture/compare/pwm module.................................................................................................. ............................................. 45 9.0 master synchronous serial port (mssp) module................................................................................ ..................................... 51 10.0 analog-to-digital converter (a/d) module ................................................................................... ............................................. 79 11.0 special features of the cpu ................................................................................................ .................................................... 87 12.0 instruction set summary.................................................................................................... ..................................................... 103 13.0 development support ........................................................................................................ ..................................................... 111 14.0 electrical characteristics................................................................................................. ........................................................ 117 15.0 dc and ac characteristics graphs and tables ................................................................................ ..................................... 139 16.0 packaging information ...................................................................................................... ...................................................... 151 appendix a: revision history ................................................................................................... ........................................................ 155 appendix b: conversion considerations........................................................................................... ................................................ 155 index .......................................................................................................................... ....................................................................... 157 on-line support................................................................................................................ ................................................................ 163 reader response ................................................................................................................ ............................................................. 164 pic16f872 product identification system ........................................................................................ ................................................ 165 to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@mail.microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/doc umentation issues become known to us, we will publis h an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particul ar device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) ? the microchip corporate literatu re center; u.s. fax: (480) 792-7277 when contacting a sales office or the literature center, pleas e specify which device, revisi on of silicon and data sheet (inclu de liter- ature number) you are using. customer notification system register on our web site at www.microchip.com/cn to receive the most current information on all of our products.
? 2006 microchip technology inc. ds30221c-page 3 pic16f872 1.0 device overview this document contains device specific information about the pic16f872 microcontroller. additional infor- mation may be found in the picmicro? mid-range reference manual (ds33023), which may be obtained from your local microchip sales representative or downloaded from the microchip website. the refer- ence manual should be considered a complementary document to this data sheet, and is highly recom- mended reading for a better understanding of the device architecture and operation of the peripheral modules. the block diagram of the pic16f872 architecture is shown in figure 1-1. a pinout description is provided in table 1-2. table 1-1: key features of the pic16f872 operating frequency dc - 20 mhz resets (and delays) por, bor (pwrt, ost) flash program memory (14-bit words) 2k data memory (bytes) 128 eeprom data memory (bytes) 64 interrupts 10 i/o ports ports a, b, c timers 3 capture/compare/pwm module 1 serial communications mssp 10-bit analog-to-digital module 5 input channels instruction set 35 instructions packaging 28-lead pdip 28-lead soic 28-lead ssop
pic16f872 ds30221c-page 4 ? 2006 microchip technology inc. figure 1-1: pic16f 872 block diagram flash program memory 13 data bus 8 14 program bus instruction reg program counter 8 level stack (13-bit) ram file registers direct addr 7 ram addr (1) 9 addr mux indirect addr fsr reg status reg mux alu w reg power-up timer oscillator start-up timer power-on reset watchdog timer instruction decode & control timing generation osc1/clkin osc2/clkout mclr v dd , v ss porta portb portc ra4/t0cki ra5/an4/ss rb0/int rc0/t1oso/t1cki rc1/t1osi/ccp2 rc2/ccp1 rc3/sck/scl rc4/sdi/sda rc5/sdo rc6 rc7 8 8 brown-out reset note 1: higher order bits are from the status register. ccp synchronous 10-bit a/d timer0 timer1 timer2 serial port ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 8 3 data eeprom rb1 rb2 rb3/pgm rb4 rb5 rb6/pgc rb7/pgd in-circuit debugger low voltage programming
? 2006 microchip technology inc. ds30221c-page 5 pic16f872 table 1-2: pic16f872 pinout description pin name pin# i/o/p type buffer type description osc1/clki osc1 clki 9 i st/cmos oscillator crystal or external clock input. oscillator crystal input or external clock source input. st buffer when configured in rc mode. otherwise cmos. external clock source input. always associated with pin function osc1 (see osc2/clko pin). osc2/clko osc2 clko 10 o ? oscillator crystal or clock output. oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. in rc mode, osc2 pin outputs clko, which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. mclr /v pp mclr v pp 1 i/p st master clear (input) or programming voltage (output). master clear (reset) input. this pin is an active low reset to the device. programming voltage input. porta is a bi-directional i/o port. ra0/an0 ra0 an0 2 i/o ttl digital i/o. analog input 0. ra1/an1 ra1 an1 3 i/o ttl digital i/o. analog input 1. ra2/an2/v ref - ra2 an2 v ref - 4 i/o ttl digital i/o. analog input 2. negative analog reference voltage. ra3/an3/v ref + ra3 an3 v ref + 5 i/o ttl digital i/o. analog input 3. positive analog reference voltage. ra4/t0cki ra4 t0cki 6i/o st digital i/o; open drain when configured as output. timer0 clock input. ra5/ss/ an4 ra5 ss an4 7 i/o ttl digital i/o. slave select for the synchronous serial port. analog input 4. legend: i = input o = output i/o = input/output p = power ? = not used ttl = ttl input st = schmitt trigger input note 1: this buffer is a schmitt trigger input when configured as the external interrupt. 2: this buffer is a schmitt trigger input when used in serial programming mode.
pic16f872 ds30221c-page 6 ? 2006 microchip technology inc. portb is a bi-directional i/o port. portb can be software programmed for internal weak pull-up on all inputs. rb0/int rb0 int 21 i/o ttl/st (1) digital i/o. external interrupt pin. rb1 22 i/o ttl digital i/o. rb2 23 i/o ttl digital i/o. rb3/pgm rb3 pgm 24 i/o ttl digital i/o. low voltage icsp programming enable pin. rb4 25 i/o ttl digital i/o. rb5 26 i/o ttl digital i/o. rb6/pgc rb6 pgc 27 i/o ttl/st (2) digital i/o. in-circuit debugger and icsp programming clock. rb7/pgd rb7 pgd 28 i/o ttl/st (2) digital i/o. in-circuit debugger and icsp programming data. portc is a bi-directional i/o port. rc0/t1oso/t1cki rc0 t1oso t1cki 11 i/o st digital i/o. timer1 oscillator output. timer1 clock input. rc1/t1osi rc1 t1osi 12 i/o st digital i/o. timer1 oscillator input. rc2/ccp1 rc2 ccp1 13 i/o st digital i/o. capture1 input/compare1 output/pwm1 output. rc3/sck/scl rc3 sck scl 14 i/o st digital i/o. synchronous serial clock input/output for spi mode. synchronous serial clock input/output for i 2 c mode. rc4/sdi/sda rc4 sdi sda 15 i/o st digital i/o. spi data in pin (spi mode). spi data i/o pin (i 2 c mode). rc5/sdo rc5 sdo 16 i/o st digital i/o. spi data out pin (spi mode). rc6 17 i/o st digital i/o. rc7 18 i/o st digital i/o. v ss 8, 19 p ? ground reference for logic and i/o pins. v dd 20 p ? positive supply for logic and i/o pins. table 1-2: pic16f872 pinout description (continued) pin name pin# i/o/p type buffer type description legend: i = input o = output i/o = input/output p = power ? = not used ttl = ttl input st = schmitt trigger input note 1: this buffer is a schmitt trigger input when configured as the external interrupt. 2: this buffer is a schmitt trigger input when used in serial programming mode.
? 2006 microchip technology inc. ds30221c-page 7 pic16f872 2.0 memory organization there are three memory blocks in the pic16f872. the program memory and data memory have separate buses so that concurrent access can occur. data mem- ory is covered in this section; the eeprom data mem- ory and flash program memory blocks are detailed in section 3.0. additional information on device memory may be found in the picmicro ? mid-range reference manual (ds33023). 2.1 program memory organization the pic16f872 has a 13-bit program counter capable of addressing an 8k word x 14 bit program memory space. the pic16f872 device actually has 2k words of flash program memory. accessing a location above the physically implemented address will cause a wrap- around. the reset vector is at 0000h and the interrupt vector is at 0004h. figure 2-1: pic16f872 program memory map and stack 2.2 data memory organization the data memory is partitioned into multiple banks which contain the general purpose registers and the special function registers. bits rp1 (status<6>) and rp0 (status<5>) are the bank select bits. each bank extends up to 7fh (128 bytes). the lower locations of each bank are reserved for the special function registers. above the special function regis- ters are general purpose registers, implemented as static ram. all implemented banks contain special function registers. some frequently used special function registers from one bank may be mirrored in another bank for code reduction and quicker access. 2.2.1 general purpose register file the register file can be accessed either directly, or indi- rectly through the file select register (fsr). pc<12:0> 13 0000h 0004h 0005h stack level 1 stack level 8 reset vector interrupt vector on-chip call, return retfie, retlw 1fffh stack level 2 program memory page 0 07ffh rp1:rp0 bank 00 0 01 1 10 2 11 3 note: eeprom data memory description can be found in section 4.0 of this data sheet.
pic16f872 ds30221c-page 8 ? 2006 microchip technology inc. figure 2-2: pic16f872 register file map indirect addr. (*) tmr0 pcl status fsr porta portb portc pclath intcon pir1 tmr1l tmr1h t1con tmr2 t2con sspbuf sspcon ccpr1l ccpr1h ccp1con option_reg pcl status fsr trisa trisb trisc pclath intcon pie1 pcon pr2 sspadd sspstat 00h 01h 02h 03h 04h 05h 06h 07h 08h 09h 0ah 0bh 0ch 0dh 0eh 0fh 10h 11h 12h 13h 14h 15h 16h 17h 18h 19h 1ah 1bh 1ch 1dh 1eh 1fh 80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 8fh 90h 91h 92h 93h 94h 95h 96h 97h 98h 99h 9ah 9bh 9ch 9dh 9eh 9fh 20h a0h 7fh ffh bank 0 bank 1 file address indirect addr. (*) indirect addr. (*) pcl status fsr pclath intcon pcl status fsr pclath intcon 100h 101h 102h 103h 104h 105h 106h 107h 108h 109h 10ah 10bh 180h 181h 182h 183h 184h 185h 186h 187h 188h 189h 18ah 18bh 17fh 1ffh bank 2 bank 3 indirect addr. (*) adresl tmr0 option_reg pir2 pie2 adresh adcon0 adcon1 general purpose register general purpose register 1efh 1f0h accesses a0h - bfh 16fh 170h accesses 70h-7fh trisb portb 96 bytes 32 bytes sspcon2 10ch 10dh 10eh 10fh 110h 18ch 18dh 18eh 18fh 190h eedata eeadr eecon1 eecon2 eedath eeadrh reserved (1) reserved (1) unimplemented data memory locations, read as '0'. * not a physical register. note 1: these registers are reserved; maintain these registers clear. 120h 1a0h accesses 70h-7fh accesses 70h-7fh accesses 20h-7fh c0h efh f0h 1c0h 1bfh bfh file address file address file address
? 2006 microchip technology inc. ds30221c-page 9 pic16f872 2.2.2 special function registers the special function registers are registers used by the cpu and peripheral modules for controlling the desired operation of the device. these registers are implemented as static ram. a list of these registers is given in table 2-1. the special function registers can be classified into two sets: core (cpu) and peripheral. those registers associated with the core functions are described in detail in this section. those related to the operation of the peripheral features are described in detail in the peripheral feature section. table 2-1: special function register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor details on page: bank 0 00h (2) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 21, 93 01h tmr0 timer0 module register xxxx xxxx 35, 93 02h (2) pcl program counter (pc) least significant byte 0000 0000 20, 93 03h (2) status irp rp1 rp0 to pd zdcc 0001 1xxx 12, 93 04h (2) fsr indirect data memory address pointer xxxx xxxx 21, 93 05h porta ? ? porta data latch when written: porta pins when read --0x 0000 29, 93 06h portb portb data latch when written: portb pins when read xxxx xxxx 31, 93 07h portc portc data latch when written: portc pins when read xxxx xxxx 33, 93 08h ? unimplemented ? ? 09h ? unimplemented ? ? 0ah (1,2) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 20, 93 0bh (2) intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 14, 93 0ch pir1 (3) adif (3) (3) sspif ccp1if tmr2if tmr1if r0rr 0000 16, 93 0dh pir2 ? (3) ?eeifbclif ? ? (3) -r-0 0--r 18, 93 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx 40, 94 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx 40, 94 10h t1con ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 39, 94 11h tmr2 timer2 module register 0000 0000 43, 94 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 43, 94 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx 55, 94 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 53, 94 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx 45, 94 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx 45, 94 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 45, 94 18h ? unimplemented ? ? 19h ? unimplemented ? ? 1ah ? unimplemented ? ? 1bh ? unimplemented ? ? 1ch ? unimplemented ? ? 1dh ? unimplemented ? ? 1eh adresh a/d result register high byte xxxx xxxx 84, 94 1fh adcon0 adcs1 adcs0 chs2 chs1 chs0 go/ done ?adon 0000 00-0 79, 94 legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0', r = reserved. shaded locations are unimplemented, read as ?0?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for the pc<12:8> whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: these bits are reserved; always maintain these bits clear.
pic16f872 ds30221c-page 10 ? 2006 microchip technology inc. bank 1 80h (2) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 21, 93 81h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 13, 94 82h (2) pcl program counter (pc) least significant byte 0000 0000 20, 93 83h (2) status irp rp1 rp0 to pd zdcc 0001 1xxx 12, 93 84h (2) fsr indirect data memory address pointer xxxx xxxx 21, 93 85h trisa ? ? porta data direction register --11 1111 29, 94 86h trisb portb data direction register 1111 1111 31, 94 87h trisc portc data direction register 1111 1111 33, 94 88h ? unimplemented ? ? 89h ? unimplemented ? ? 8ah (1,2) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 20, 93 8bh (2) intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 14, 93 8ch pie1 (3) adie (3) (3) sspie ccp1ie tmr2ie tmr1ie r0rr 0000 15, 94 8dh pie2 ? (3) ?eeiebclie ? ? (3) -r-0 0--r 17, 94 8eh pcon ? ? ? ? ? ?por bor ---- --qq 19, 94 8fh ? unimplemented ? ? 90h ? unimplemented ? ? 91h sspcon2 gcen ackstat ackdt acken rcen pen rsen sen 0000 0000 54, 94 92h pr2 timer2 period register 1111 1111 43, 94 93h sspadd synchronous serial port (i 2 c mode) address register 0000 0000 58, 94 94h sspstat smp cke d/a psr/w ua bf 0000 0000 52, 94 95h ? unimplemented ? ? 96h ? unimplemented ? ? 97h ? unimplemented ? ? 95h ? unimplemented ? ? 95h ? unimplemented ? ? 9ah ? unimplemented ? ? 9bh ? unimplemented ? ? 9ch ? unimplemented ? ? 9dh ? unimplemented ? ? 9eh adresl a/d result register low byte xxxx xxxx 84, 94 9fh adcon1 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 0--- 0000 80, 94 table 2-1: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor details on page: legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0', r = reserved. shaded locations are unimplemented, read as ?0?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for the pc<12:8> whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: these bits are reserved; always maintain these bits clear.
? 2006 microchip technology inc. ds30221c-page 11 pic16f872 bank 2 100h (2) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 21, 93 101h tmr0 timer0 module register xxxx xxxx 35, 93 102h (2) pcl program counter (pc) least significant byte 0000 0000 20, 93 103h (2) status irp rp1 rp0 to pd zdcc 0001 1xxx 12, 93 104h (2) fsr indirect data memory address pointer xxxx xxxx 21, 93 105h ? unimplemented ? ? 106h portb portb data latch when written: portb pins when read xxxx xxxx 31, 93 107h ? unimplemented ? ? 108h ? unimplemented ? ? 109h ? unimplemented ? ? 10ah (1,2) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 20, 93 10bh (2) intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 14, 93 10ch eedata eeprom data register low byte xxxx xxxx 23, 94 10dh eeadr eeprom address register low byte xxxx xxxx 23, 94 10eh eedath ? ? eeprom data register high byte xxxx xxxx 23, 94 10fh eeadrh ? ? ? eeprom address register high byte xxxx xxxx 23, 94 bank 3 180h (2) indf addressing this location uses contents of fsr to address data memory (not a physical register) 0000 0000 21, 93 181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 13, 94 182h (2) pcl program counter (pc) least significant byte 0000 0000 20, 93 183h (2) status irp rp1 rp0 to pd zdcc 0001 1xxx 12, 93 184h (2) fsr indirect data memory address pointer xxxx xxxx 21, 93 185h ? unimplemented ? ? 186h trisb portb data direction register 1111 1111 31, 94 187h ? unimplemented ? ? 188h ? unimplemented ? ? 189h ? unimplemented ? ? 18ah (1,2) pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 20, 93 18bh (2) intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 14, 93 18ch eecon1 eepgd ? ? ? wrerr wren wr rd x--- x000 24, 94 18dh eecon2 eeprom control regist er2 (not a physical register) ---- ---- 23, 94 18eh ? reserved; maintain clear 0000 0000 ? 18fh ? reserved; maintain clear 0000 0000 ? table 2-1: special function register summary (continued) address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor details on page: legend: x = unknown, u = unchanged, q = value depends on condition, - = unimplemented, read as '0', r = reserved. shaded locations are unimplemented, read as ?0?. note 1: the upper byte of the program counter is not directly accessible. pclath is a holding register for the pc<12:8> whose contents are transferred to the upper byte of the program counter. 2: these registers can be addressed from any bank. 3: these bits are reserved; always maintain these bits clear.
pic16f872 ds30221c-page 12 ? 2006 microchip technology inc. 2.2.2.1 status register the status register contains the arithmetic status of the alu, the reset status and the bank select bits for data memory. the status register can be the destination for any instruction, as with any other register. if the status register is the destination for an instruction that affects the z, dc or c bits, then the write to these three bits is disabled. these bits are set or cleared according to the device logic. furthermore, the to and pd bits are not writable, therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will clear the upper three bits and set the z bit. this leaves the status register as 000u u1uu (where u = unchanged). it is recommended, therefore, that only bcf, bsf, swapf and movwf instructions are used to alter the status register, because these instructions do not affect the z, c or dc bits from the status register. for other instructions not affecting any status bits, see the ?instruction set summary." register 2-1: status register (address: 03h, 83h, 103h, 183h) note: the c and dc bits operate as a borrow and digit borrow bit, respectively, in sub- traction. see the sublw and subwf instructions for examples. r/w-0 r/w-0 r/w-0 r-1 r-1 r/w-x r/w-x r/w-x irp rp1 rp0 to pd zdcc bit 7 bit 0 bit 7 irp: register bank select bit (used for indirect addressing) 1 = bank 2, 3 (100h - 1ffh) 0 = bank 0, 1 (00h - ffh) bit 6:5 rp1:rp0 : register bank select bits (used for direct addressing) 11 = bank 3 (180h - 1ffh) 10 = bank 2 (100h - 17fh) 01 = bank 1 (80h - ffh) 00 = bank 0 (00h - 7fh) each bank is 128 bytes bit 4 to : time-out bit 1 = after power-up, clrwdt instruction, or sleep instruction 0 = a wdt time-out occurred bit 3 pd : power-down bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 2 z : zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc : digit carry/borrow bit ( addwf , addlw,sublw,subwf instructions) (for borrow the polarity is reversed) 1 = a carry-out from the 4th low order bit of the result occurred 0 = no carry-out from the 4th low order bit of the result bit 0 c : carry/borrow bit ( addwf , addlw,sublw,subwf instructions) 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note: for borrow the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. for rotate ( rrf, rlf ) instructions, this bit is loaded with either the high or low order bit of the source register. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2006 microchip technology inc. ds30221c-page 13 pic16f872 2.2.2.2 option_reg register the option_reg register is a readable and writable register, which contains various control bits to configure the tmr0 prescaler/wdt postscaler (single assign- able register known also as the prescaler), the external int interrupt, tmr0 and the weak pull-ups on portb. register 2-2: option_reg register (address 81h, 181h) note: to achieve a 1:1 prescaler assignment for the tmr0 register, assign the prescaler to the watchdog timer. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg : interrupt edge select bit 1 = interrupt on rising edge of rb0/int pin 0 = interrupt on falling edge of rb0/int pin bit 5 t0cs : tmr0 clock source select bit 1 = transition on ra4/t0cki pin 0 = internal instruction cycle clock (clkout) bit 4 t0se : tmr0 source edge select bit 1 = increment on high-to-low transition on ra4/t0cki pin 0 = increment on low-to-high transition on ra4/t0cki pin bit 3 psa : prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps2:ps0 : prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown note: when using low voltage icsp programming (lvp) and the pull-ups on portb are enabled, bit 3 in the trisb register must be cleared to disable the pull-up on rb3 and ensure the proper oper- ation of the device 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate
pic16f872 ds30221c-page 14 ? 2006 microchip technology inc. 2.2.2.3 intcon register the intcon register is a readable and writable regis- ter, which contains various enable and flag bits for the tmr0 register overflow, rb port change and external rb0/int pin interrupts. register 2-3: intcon register (address: 0bh, 8bh, 10bh, 18bh) note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user soft- ware should ensure the appropriate inter- rupt flag bits are clear prior to enabling an interrupt. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie peietmr0ieinte rbietmr0ifintf rbif bit 7 bit 0 bit 7 gie: global interrupt enable bit 1 = enables all unmasked interrupts 0 = disables all interrupts bit 6 peie : peripheral interrupt enable bit 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts bit 5 tmr0ie : tmr0 overflow interrupt enable bit 1 = enables the tmr0 interrupt 0 = disables the tmr0 interrupt bit 4 inte : rb0/int external interrupt enable bit 1 = enables the rb0/int external interrupt 0 = disables the rb0/int external interrupt bit 3 rbie : rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 tmr0if : tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 intf : rb0/int external interrupt flag bit 1 = the rb0/int external interrupt occurred (must be cleared in software) 0 = the rb0/int external interrupt did not occur bit 0 rbif : rb port change interrupt flag bit 1 = at least one of the rb7:rb4 pins changed state; a mismatch condition will continue to set the bit. reading portb will end the mismatch condition and allow the bit to be cleared (must be cleared in software). 0 = none of the rb7:rb4 pins have changed state legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2006 microchip technology inc. ds30221c-page 15 pic16f872 2.2.2.4 pie1 register the pie1 register contains the individual enable bits for the peripheral interrupts. register 2-4: pie1 register (address: 8ch) note: bit peie (intcon<6>) must be set to enable any peripheral interrupt. r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 reserved adie reserved reserved sspie ccp1ie tmr2ie tmr1ie bit 7 bit 0 bit 7 reserved: always maintain these bits clear bit 6 adie : a/d converter interrupt enable bit 1 = enables the a/d converter interrupt 0 = disables the a/d converter interrupt bit 5-4 reserved: always maintain these bits clear bit 3 sspie : synchronous serial port interrupt enable bit 1 = enables the ssp interrupt 0 = disables the ssp interrupt bit 2 ccp1ie : ccp1 interrupt enable bit 1 = enables the ccp1 interrupt 0 = disables the ccp1 interrupt bit 1 tmr2ie : tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie : tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f872 ds30221c-page 16 ? 2006 microchip technology inc. 2.2.2.5 pir1 register the pir1 register contains the individual flag bits for the peripheral interrupts. note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user soft- ware should ensure the appropriate inter- rupt bits are clear prior to enabling an interrupt. register 2-5: pir1 register (address: 0ch) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 reserved adif reserved reserved sspif ccp1if tmr2if tmr1if bit 7 bit 0 bit 7 reserved: always maintain these bits clear bit 6 adif : a/d converter interrupt flag bit 1 = an a/d conversion completed 0 = the a/d conversion is not complete bit 5-4 reserved: always maintain these bits clear bit 3 sspif : synchronous serial port (ssp) interrupt flag 1 = the ssp interrupt condition has occurred, and must be cleared in software before returning from the interrupt service routine. the conditions that will set this bit are: ? spi - a transmission/reception has taken place ? i 2 c slave - a transmission/reception has taken place ?i 2 c master - a transmission/reception has taken place - the initiated start condition was completed by the ssp module - the initiated stop condition was completed by the ssp module - the initiated restart condition was completed by the ssp module - the initiated acknowledge condition was completed by the ssp module - a start condition occurred while the ssp module was idle (multi-master system) - a stop condition occurred while the ssp module was idle (multi-master system) 0 = no ssp interrupt condition has occurred bit 2 ccp1if : ccp1 interrupt flag bit capture mode: 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode: 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode: unused in this mode bit 1 tmr2if : tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if : tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2006 microchip technology inc. ds30221c-page 17 pic16f872 2.2.2.6 pie2 register the pie2 register contains the individual enable bits for the ccp2 peripheral interrupt, the ssp bus collision interrupt, and the eeprom write operation interrupt. register 2-6: pie2 register (address: 8dh) u-0 r/w-0 u-0 r/w-0 r/w-0 u-0 u-0 r/w-0 ? reserved ? eeie bclie ? ? reserved bit 7 bit 0 bit 7 unimplemented: read as '0' bit 6 reserved : always maintain this bit clear bit 5 unimplemented: read as '0' bit 4 eeie : eeprom write operation interrupt enable bit 1 = enable eeprom write interrupt 0 = disable eeprom write interrupt bit 3 bclie : bus collision interrupt enable bit 1 = enable bus collision interrupt 0 = disable bus collision interrupt bit 2-1 unimplemented: read as '0' bit 0 reserved : always maintain this bit clear legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f872 ds30221c-page 18 ? 2006 microchip technology inc. 2.2.2.7 pir2 register the pir2 register contains the flag bits for the ccp2 interrupt, the ssp bus collision interrupt and the eeprom write operation interrupt. . register 2-7: pir2 register (address: 0dh) note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie (intcon<7>). user soft- ware should ensure the appropriate inter- rupt flag bits are clear prior to enabling an interrupt. u-0 r/w-0 u-0 r/w-0 r/w-0 u-0 u-0 r/w-0 ? reserved ? eeif bclif ? ? reserved bit 7 bit 0 bit 7 unimplemented: read as '0' bit 6 reserved : always maintain this bit clear bit 5 unimplemented: read as '0' bit 4 eeif : eeprom write operation interrupt flag bit 1 = the write operation completed (must be cleared in software) 0 = the write operation is not complete or has not been started bit 3 bclif : bus collision interrupt flag bit 1 = a bus collision has occurred in the ssp, when configured for i 2 c master mode 0 = no bus collision has occurred bit 2-1 unimplemented: read as '0' bit 0 reserved : always maintain this bit clear legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2006 microchip technology inc. ds30221c-page 19 pic16f872 2.2.2.8 pcon register the power control (pcon) register contains flag bits to allow differentiation between a power-on reset (por), a brown-out reset (bor), a watchdog reset (wdt) and an external mclr reset. register 2-8: pcon register (address: 8eh) note: bor is unknown on por. it must be set by the user and checked on subsequent resets to see if bor is clear, indicating a brown-out has occurred. the bor status bit is a don?t care and is not predictable if the brown-out circuit is disabled (by clear- ing the boden bit in the configuration word). u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-1 ? ? ? ? ? ?por bor bit 7 bit 0 bit 7-2 unimplemented: read as '0' bit 1 por : power-on reset status bit 1 = no power-on reset occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = no brown-out reset occurred 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f872 ds30221c-page 20 ? 2006 microchip technology inc. 2.3 pcl and pclath the program counter (pc) is 13-bits wide. the low byte comes from the pcl register, which is a readable and writable register. the upper bits (pc<12:8>) are not readable, but are indirectly writable through the pclath register. on any reset, the upper bits of the pc will be cleared. figure 2-3 shows the two situations for the loading of the pc. the upper example in the fig- ure shows how the pc is loaded on a write to pcl (pclath<4:0> pch). the lower example in the fig- ure shows how the pc is loaded during a call or goto instruction (pclath<4:3> pch). figure 2-3: loading of pc in different situations 2.3.1 computed goto a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). when doing a table read using a computed goto method, care should be exercised if the table location crosses a pcl memory boundary (each 256 byte block). refer to the application note, ?implementing a table read" (an556). 2.3.2 stack the pic16fxxx family has an 8-level deep x 13-bit wide hardware stack. the stack space is not part of either program or data space and the stack pointer is not readable or writable. the pc is pushed onto the stack when a call instruction is executed or an inter- rupt causes a branch. the stack is poped in the event of a return, retlw or a retfie instruction execu- tion. pclath is not affected by a push or pop oper- ation. the stack operates as a circular buffer. this means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored from the first push. the tenth push overwrites the second push (and so on). 2.4 program memory paging all pic16fxxx devices are capable of addressing a continuous 8k word block of program memory. the call and goto instructions provide only 11 bits of address to allow branching within any 2k program memory page. when doing a call or goto instruction, the upper 2 bits of the address are provided by pclath<4:3>. since the pic16f872 has only 2k words of program memory or one page, additional code is not required to ensure that the correct page is selected before a call or goto instruction is exe- cuted. the pclath<4:3> bits should always be main- tained as zeros. if a return from a call instruction (or interrupt) is executed, the entire 13-bit pc is popped off the stack. therefore, manipulation of the pclath<4:3> bits are not required for the return instructions (which pops the address from the stack). pc 12 8 7 0 5 pclath<4:0> pclath instruction with alu goto,call opcode <10:0> 8 pc 12 11 10 0 11 pclath<4:3> pch pcl 87 2 pclath pch pcl pcl as destination note 1: there are no status bits to indicate stack overflow or stack underflow conditions. 2: there are no instructions/mnemonics called push or pop. these are actions that occur from the execution of the call, return, retlw and retfie instructions, or the vectoring to an inter- rupt address. note: the contents of the pclath register are unchanged after a return or retfie instruction is executed. the user must rewrite the contents of the pclath regis- ter for any subsequent subroutine calls or goto instructions.
? 2006 microchip technology inc. ds30221c-page 21 pic16f872 2.5 indirect addressing, indf and fsr registers the indf register is not a physical register. addressing the indf register will cause indirect addressing. indirect addressing is possible by using the indf reg- ister. any instruction using the indf register actually accesses the register pointed to by the file select reg- ister, fsr. reading the indf register itself indirectly (fsr = ' 0 '), will read 00h. writing to the indf register indirectly results in a no operation (although status bits may be affected). an effective 9-bit address is obtained by concatenating the 8-bit fsr register and the irp bit (status<7>), as shown in figure 2-4. a simple program to clear ram locations 20h-2fh using indirect addressing is shown in example 2-1. example 2-1: indirect addressing figure 2-4: direct/indirect addressing movlw 0x20 ;initialize pointer movwf fsr ;to ram next clrf indf ;clear indf register incf fsr,f ;inc pointer btfss fsr,4 ;all done? goto next ;no clear next continue : ;yes continue note 1: for register file map detail, see figure 2-2. data memory (1) indirect addressing direct addressing bank select location select rp1:rp0 6 0 from opcode irp fsr register 7 0 bank select location select 00 01 10 11 bank 0 bank 1 bank 2 bank 3 ffh 80h 7fh 00h 17fh 100h 1ffh 180h
pic16f872 ds30221c-page 22 ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. ds30221c-page 23 pic16f872 3.0 data eeprom and flash program memory the data eeprom and flash program memory are readable and writable during normal operation over the entire v dd range. these operations take place on a sin- gle byte for data eeprom memory and a single word for program memory. a write operation causes an erase-then-write operation to take place on the speci- fied byte or word. a bulk erase operation may not be issued from user code (which includes removing code protection). access to program memory allows for checksum calcu- lation. the values written to program memory do not need to be valid instructions. therefore, numbers of up to 14 bits can be stored in memory for use as calibra- tion parameters, serial numbers, packed 7-bit ascii, etc. executing a program memory location, containing data that forms an invalid instruction, results in the exe- cution of a nop instruction. the eeprom data memory is rated for high erase/ write cycles (specification #d120). the flash pro- gram memory is rated much lower (specification #d130) because eeprom data memory can be used to store frequently updated values. an on-chip timer controls the write time and it will vary with voltage and temperature, as well as from chip to chip. please refer to the specifications for exact limits (specifications #d122 and #d133). a byte or word write automatically erases the location and writes the new value (erase before write). writing to eeprom data memory does not impact the opera- tion of the device. writing to program memory will cease the execution of instructions until the write is complete. the program memory cannot be accessed during the write. during the write operation, the oscilla- tor continues to run, the peripherals continue to func- tion and interrupt events will be detected and essentially ?queued? until the write is complete. when the write completes, the next instruction in the pipeline is executed and the branch to the interrupt vector will take place if the interrupt is enabled and occurred dur- ing the write. read and write access to both memories take place indirectly through a set of special function registers (sfr). the six sfrs used are: ? eedata ? eedath ? eeadr ? eeadrh ? eecon1 ? eecon2 the eeprom data memory allows byte read and write operations without interfering with the normal operation of the microcontroller. when interfacing to eeprom data memory, the eeadr register holds the address to be accessed. depending on the operation, the eedata register holds the data to be written or the data read at the address in eeadr. the pic16f872 has 64 bytes of eeprom data memory and therefore, requires that the two most significant bits of eeadr remain clear. eeprom data memory on these devices wraps around to 0 (i.e., 40h in the eeadr maps to 00h). the flash program memory allows non-intrusive read access, but write operations cause the device to stop executing instructions until the write completes. when interfacing to the program memory, the eeadrh:eeadr registers pair forms a two-byte word which holds the 13-bit address of the memory location being accessed. the eedath:eedata register pair holds the 14-bit data for writes or reflects the value of program memory after a read operation. just as in eeprom data memory accesses, the value of the eeadrh:eeadr registers must be within the valid range of program memory, depending on the device (0000h to 07ffh). addresses outside of this range wrap around to 0000h (i.e., 0800h maps to 0000h). 3.1 eecon1 and eecon2 registers the eecon1 register is the control register for config- uring and initiating the access. the eecon2 register is not a physically implemented register, but is used exclusively in the memory write sequence to prevent inadvertent writes. there are many bits used to control the read and write operations to eeprom data and flash program memory. the eepgd bit determines if the access will be a program or data memory access. when clear, any subsequent operations will work on the eeprom data memory. when set, all subsequent operations will operate in the program memory. read operations only use one additional bit, rd, which initiates the read operation from the desired memory location. once this bit is set, the value of the desired memory location will be available in the data registers. this bit cannot be cleared by firmware. it is automati- cally cleared at the end of the read operation. for eeprom data memory reads, the data will be avail- able in the eedata register in the very next instruction cycle after the rd bit is set. for program memory reads, the data will be loaded into the eedath:eedata registers, following the second instruction after the rd bit is set.
pic16f872 ds30221c-page 24 ? 2006 microchip technology inc. write operations have two control bits, wr and wren, and two status bits, wrerr and eeif. the wren bit is used to enable or disable the write operation. when wren is clear, the write operation will be disabled. therefore, the wren bit must be set before executing a write operation. the wr bit is used to initiate the write operation. it also is automatically cleared at the end of the write operation. the interrupt flag eeif (located in register pir2) is used to determine when the memory write completes. this flag must be cleared in software before setting the wr bit. for eeprom data memory, once the wren bit and the wr bit have been set, the desired memory address in eeadr will be erased fol- lowed by a write of the data in eedata. this operation takes place in parallel with the microcontroller continu- ing to execute normally. when the write is complete, the eeif flag bit will be set. for program memory, once the wren bit and the wr bit have been set, the micro- controller will cease to execute instructions. the desired memory location pointed to by eeadrh:eeadr will be erased. then the data value in eedath:eedata will be programmed. when com- plete, the eeif flag bit will be set and the microcontrol- ler will continue to execute code. the wrerr bit is used to indicate when the device has been reset during a write operation. wrerr should be cleared after power-on reset. thereafter, it should be checked on any other reset. the wrerr bit is set when a write operation is interrupted by a mclr reset or a wdt time-out reset during normal operation. in these situations, following a reset, the user should check the wrerr bit and rewrite the memory location if set. the contents of the data regis- ters, address registers and eepgd bit are not affected by either mclr reset or wdt time-out reset during normal operation. register 3-1: eecon1 register (address 18ch) r/w-x u-0 u-0 u-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd ? ? ? wrerr wren wr rd bit 7 bit 0 bit 7 eepgd : program/data eeprom select bit 1 = accesses program memory 0 = accesses data memory (this bit cannot be changed while a read or write operation is in progress.) bit 6-4 unimplemented: read as '0' bit 3 wrerr : eeprom error flag bit 1 = a write operation is prematurely terminated (any mclr reset or any wdt reset during normal operation) 0 = the write operation completed bit 2 wren : eeprom write enable bit 1 = allows write cycles 0 = inhibits write to the eeprom bit 1 wr : write control bit 1 = initiates a write cycle (the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd : read control bit 1 = initiates an eeprom read rd is cleared in hardware. the rd bit can only be set (not cleared) in software. 0 = does not initiate an eeprom read legend: s = settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2006 microchip technology inc. ds30221c-page 25 pic16f872 3.2 reading the eeprom data memory reading eeprom data memory only requires that the desired address to access be written to the eeadr register and clear the eepgd bit. after the rd bit is set, data will be available in the eedata register on the very next instruction cycle. eedata will hold this value until another read operation is initiated or until it is writ- ten by firmware. the steps to reading the eeprom data memory are: 1. write the address to eedata. make sure that the address is not larger than the memory size of the device. 2. clear the eepgd bit to point to eeprom data memory. 3. set the rd bit to start the read operation. 4. read the data from the eedata register. example 3-1: eeprom data read 3.3 writing to the eeprom data memory there are many steps in writing to the eeprom data memory. both address and data values must be written to the sfrs. the eepgd bit must be cleared and the wren bit must be set to enable writes. the wren bit should be kept clear at all times, except when writing to the eeprom data. the wr bit can only be set if the wren bit was set in a previous operation, i.e., they both cannot be set in the same operation. the wren bit should then be cleared by firmware after the write. clearing the wren bit before the write actually com- pletes will not terminate the write in progress. writes to eeprom data memory must also be pref- aced with a special sequence of instructions that pre- vent inadvertent write operations. this is a sequence of five instructions that must be executed without interrup- tion for each byte written. the steps to write to program memory are: 1. write the address to eeadr. make sure that the address is not larger than the memory size of the device. 2. write the 8-bit data value to be programmed in the eedata registers. 3. clear the eepgd bit to point to eeprom data memory. 4. set the wren bit to enable program operations. 5. disable interrupts (if enabled). 6. execute the special five instruction sequence: ? write 55h to eecon2 in two steps (first to w, then to eecon2) ? write aah to eecon2 in two steps (first to w, then to eecon2) ? set the wr bit 7. enable interrupts (if using interrupts). 8. clear the wren bit to disable program operations. 9. at the completion of the write cycle, the wr bit is cleared and the eeif interrupt flag bit is set. (eeif must be cleared by firmware). firmware may check for eeif to be set or wr to clear to indicate end of program cycle. example 3-2: eeprom data write bsf status, rp1 ; bcf status, rp0 ;bank 2 movf addr, w ;write address movwf eeadr ;to read from bsf status, rp0 ;bank 3 bcf eecon1, eepgd ;point to data memory bsf eecon1, rd ;start read operation bcf status, rp0 ;bank 2 movf eedata, w ;w = eedata bsf status, rp1 ; bcf status, rp0 ;bank 2 movf addr, w ;address to movwf eeadr ;write to movf value, w ;data to movwf eedata ;write bsf status, rp0 ;bank 3 bcf eecon1, eepgd ;point to data memory bsf eecon1, wren ;enable writes ;only disable interrupts bcf intcon, gie ;if already enabled, ;otherwise discard movlw 0x55 ;write 55h to movwf eecon2 ;eecon2 movlw 0xaa ;write aah to movwf eecon2 ;eecon2 bsf eecon1, wr ;start write operation ;only enable interrupts bsf intcon, gie ;if using interrupts, ;otherwise discard bcf eecon1, wren ;disable writes required sequence
pic16f872 ds30221c-page 26 ? 2006 microchip technology inc. 3.4 reading the flash program memory reading flash program memory is much like that of eeprom data memory, only two nop instructions must be inserted after the rd bit is set. these two instruction cycles that the nop instructions execute will be used by the microcontroller to read the data out of program memory and insert the value into the eedath:eedata registers. data will be available fol- lowing the second nop instruction. eedath and eedata will hold their value until another read opera- tion is initiated, or until they are written by firmware. the steps to reading the flash program memory are: 1. write the address to eeadrh:eeadr. make sure that the address is not larger than the mem- ory size of the device. 2. set the eepgd bit to point to flash program memory. 3. set the rd bit to start the read operation. 4. execute two nop instructions to allow the micro- controller to read out of program memory. 5. read the data from the eedath:eedata registers. example 3-3: flash program read 3.5 writing to the flash program memory writing to flash program memory is unique in that the microcontroller does not execute instructions while pro- gramming is taking place. the oscillator continues to run and all peripherals continue to operate and queue interrupts, if enabled. once the write operation com- pletes (specification #d133), the processor begins exe- cuting code from where it left off. the other important difference when writing to flash program memory is that the wrt configuration bit, when clear, prevents any writes to program memory (see table 3-1). just like eeprom data memory, there are many steps in writing to the flash program memory. both address and data values must be written to the sfrs. the eepgd bit must be set and the wren bit must be set to enable writes. the wren bit should be kept clear at all times, except when writing to the flash program memory. the wr bit can only be set if the wren bit was set in a previous operation, i.e., they both cannot be set in the same operation. the wren bit should then be cleared by firmware after the write. clearing the wren bit before the write actually com- pletes will not terminate the write in progress. writes to program memory must also be prefaced with a special sequence of instructions that prevent inad- vertent write operations. this is a sequence of five instructions that must be executed without interruption for each byte written. these instructions must then be followed by two nop instructions to allow the microcon- troller to setup for the write operation. once the write is complete, the execution of instructions starts with the instruction after the second nop . bsf status, rp1 ; bcf status, rp0 ;bank 2 movf addrl, w ;write the movwf eeadr ;address bytes movf addrh,w ;for the desired movwf eeadrh ;address to read bsf status, rp0 ;bank 3 bsf eecon1, eepgd ;point to program memory bsf eecon1, rd ;start read operation nop ;required two nops nop ; bcf status, rp0 ;bank 2 movf eedata, w ;datal = eedata movwf datal ; movf eedath,w ;datah = eedath movwf datah ; required sequence
? 2006 microchip technology inc. ds30221c-page 27 pic16f872 the steps to write to program memory are: 1. write the address to eeadrh:eeadr. make sure that the address is not larger than the mem- ory size of the device. 2. write the 14-bit data value to be programmed in the eedath:eedata registers. 3. set the eepgd bit to point to flash program memory. 4. set the wren bit to enable program operations. 5. disable interrupts (if enabled). 6. execute the special five instruction sequence: ? write 55h to eecon2 in two steps (first to w, then to eecon2) ? write aah to eecon2 in two steps (first to w, then to eecon2) ? set the wr bit 7. execute two nop instructions to allow the micro- controller to setup for write operation. 8. enable interrupts (if using interrupts). 9. clear the wren bit to disable program operations. at the completion of the write cycle, the wr bit is cleared and the eeif interrupt flag bit is set. (eeif must be cleared by firmware). since the microcontroller does not execute instructions during the write cycle, the firmware does not necessarily have to check either eeif or wr to determine if the write had finished. example 3-4: flash program write 3.6 write verify the pic16f87x devices do not automatically verify the value written during a write operation. depending on the application, good programming practice may dic- tate that the value written to memory be verified against the original value. this should be used in applications where excessive writes can stress bits near the speci- fied endurance limits. 3.7 protection against spurious writes there are conditions when the device may not want to write to the eeprom data memory or flash program memory. to protect against these spurious write condi- tions various mechanisms have been built into the device. on power-up, the wren bit is cleared and the power-up timer (if enabled) prevents writes. the write initiate sequence and the wren bit together help prevent any accidental writes during brown-out, power glitches or firmware malfunction. bsf status, rp1 ; bcf status, rp0 ;bank 2 movf addrl, w ;write address movwf eeadr ;of desired movf addrh, w ;program memory movwf eeadrh ;location movf valuel, w ;write value to movwf eedata ;program at movf valueh, w ;desired memory movwf eedath ;location bsf status, rp0 ;bank 3 bsf eecon1, eepgd ;point to program memory bsf eecon1, wren ;enable writes ;only disable interrupts bcf intcon, gie ;if already enabled, ;otherwise discard movlw 0x55 ;write 55h to movwf eecon2 ;eecon2 movlw 0xaa ;write aah to movwf eecon2 ;eecon2 bsf eecon1, wr ;start write operation nop ;two nops to allow micro nop ;to setup for write ;only enable interrupts bsf intcon, gie ;if using interrupts, ;otherwise discard bcf eecon1, wren ;disable writes required sequence
pic16f872 ds30221c-page 28 ? 2006 microchip technology inc. 3.8 operation while code protected the pic16f872 has two code protect mechanisms, one bit for eeprom data memory and two bits for flash program memory. data can be read and written to the eeprom data memory regardless of the state of the code protection bit, cpd. when code protection is enabled, cpd cleared, external access via icsp is disabled regardless of the state of the program memory code protect bits. this prevents the contents of eeprom data memory from being read out of the device. the state of the program memory code protect bits, cp0 and cp1, do not affect the execution of instruc- tions out of program memory. the pic16f872 can always read the values in program memory, regardless of the state of the code protect bits. however, the state of the code protect bits and the wrt bit will have differ- ent effects on writing to program memory. table 4-1 shows the effect of the code protect bits and the wrt bit on program memory. once code protection has been enabled for either eeprom data memory or flash program memory, only a full erase of the entire device will disable code protection. 3.9 flash program memory write protection the configuration word contains a bit that write protects the flash program memory called wrt. this bit can only be accessed when programming the device via icsp. once write protection is enabled, only an erase of the entire device will disable it. when enabled, write protection prevents any writes to flash program memory. write protection does not affect program memory reads. table 3-1: read/write state of internal flash program memory table 3-2: registers associated with data eeprom/program flash configuration bits memory location internal read internal write icsp read icsp write cp1 cp0 wrt 000 all program memory yes no no no 001 all program memory yes yes no no 110 all program memory yes no yes yes 111 all program memory yes yes yes yes address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 10dh eeadr eeprom address register, low byte xxxx xxxx uuuu uuuu 10fh eeadrh ? ? ? eeprom address, high byte xxxx xxxx uuuu uuuu 10ch eedata eeprom data register, low byte xxxx xxxx uuuu uuuu 10eh eedath ? ? eeprom data register, high byte xxxx xxxx uuuu uuuu 18ch eecon1 eepgd ? ? ? wrerr wren wr rd x--- x000 x--- u000 18dh eecon2 eeprom control register2 (not a physical register) ? ? 8dh pie2 ? (1) ?eeie bclie ? ? (1) -r-0 0--r -r-0 0--r 0dh pir2 ? (1) ?eeif bclif ? ? (1) -r-0 0--r -r-0 0--r legend: x = unknown, u = unchanged, r = reserved, - = unimplemented, read as '0'. shaded cells are not used during flash/eeprom access. note 1: these bits are reserved; always maintain these bits clear.
? 2006 microchip technology inc. ds30221c-page 29 pic16f872 4.0 i/o ports the pic16f872 provides three general purpose i/o ports. some pins for these ports are multiplexed with an alternate function for the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. additional information on i/o ports may be found in the picmicro? mid-range reference manual (ds33023). 4.1 porta and the trisa register porta is a 6-bit wide, bi-directional port. the corre- sponding data direction register is trisa. setting a trisa bit (= ? 1 ?) will make the corresponding porta pin an input (i.e., put the corresponding output driver in a hi-impedance mode). clearing a trisa bit (= ? 0 ?) will make the corresponding porta pin an output (i.e., put the contents of the output latch on the selected pin). reading the porta register reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, the value is modified and then written to the port data latch. pin ra4 is multiplexed with the timer0 module clock input to become the ra4/t0cki pin. the ra4/t0cki pin is a schmitt trigger input and an open drain output. all other porta pins have ttl input levels and full cmos output drivers. other porta pins are multiplexed with analog inputs and analog v ref input. the operation of each pin is selected by clearing/setting the control bits in the adcon1 register (a/d control register1). the trisa register controls the direction of the ra pins, even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. example 4-1: initializing porta figure 4-1: block diagram of ra3:ra0 and ra5 pins figure 4-2: block diagram of ra4/t0cki pin note: on a power-on reset, these pins are con- figured as analog inputs and read as '0'. bcf status, rp0 ; bcf status, rp1 ; bank0 clrf porta ; initialize porta by ; clearing output ; data latches bsf status, rp0 ; select bank 1 movlw 0x06 ; configure all pins movwf adcon1 ; as digital inputs movlw 0xcf ; value used to ; initialize data ; direction movwf trisa ; set ra<3:0> as inputs ; ra<5:4> as outputs ; trisa<7:6>are always ; read as '0'. data bus p n wr port wr tris data latch tris latch rd rd port v ss v dd i/o pin (1) note 1: i/o pins have protection diodes to v dd and v ss . analog input mode ttl input buffer to a/d converter tris en qd en q d q ck q d q ck data bus wr port wr tris rd port data latch tris latch rd schmitt trigger input buffer n v ss i/o pin (1) tmr0 clock input q d q ck q d q ck en qd en note 1: i/o pin has protection diodes to v ss only. tris
pic16f872 ds30221c-page 30 ? 2006 microchip technology inc. table 4-1: porta functions table 4-2: summary of registers associated with porta name bit# buffer function ra0/an0 bit0 ttl input/output or analog input. ra1/an1 bit1 ttl input/output or analog input. ra2/an2 bit2 ttl input/output or analog input. ra3/an3/v ref bit3 ttl input/output or analog input or v ref. ra4/t0cki bit4 st input/output or external clock input for timer0. output is open drain type. ra5/ss /an4 bit5 ttl input/output or slave select input for synchronous serial port or analog input. legend: ttl = ttl input, st = schmitt trigger input address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 05h porta ? ? ra5 ra4 ra3 ra2 ra1 ra0 --0x 0000 --0u 0000 85h trisa ? ? porta data direction register --11 1111 --11 1111 9fh adcon1 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 --0- 0000 --0- 0000 legend: x = unknown, u = unchanged, - = unimplemented locations read as '0'. shaded cells are not used by porta. note: when using the ssp module in spi slave mode and ss enabled, the a/d converter must be set to one of the following modes, where pcfg3:pcfg0 = 0100, 0101, 011x, 1101, 1110, 1111 .
? 2006 microchip technology inc. ds30221c-page 31 pic16f872 4.2 portb and the trisb register portb is an 8-bit wide, bi-directional port. the corre- sponding data direction register is trisb. setting a trisb bit (= ? 1 ?) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a hi-impedance mode). clearing a trisb bit (= ? 0 ?) will make the corresponding portb pin an output (i.e., put the contents of the output latch on the selected pin). three pins of portb are multiplexed with the low voltage programming function; rb3/pgm, rb6/pgc and rb7/pgd. the alternate functions of these pins are described in the special features section. each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is per- formed by clearing bit rbpu (option_reg<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are dis- abled on a power-on reset. figure 4-3: block diagram of rb3:rb0 pins four of the portb pins, rb7:rb4, have an interrupt- on-change feature. only pins configured as inputs can cause this interrupt to occur (i.e., any rb7:rb4 pin configured as an output is excluded from the interrupt- on-change comparison). the input pins (of rb7:rb4) are compared with the old value latched on the last read of portb. the ?mismatch? outputs of rb7:rb4 are or?ed together to generate the rb port change interrupt with flag bit rbif (intcon<0>). this interrupt can wake the device from sleep. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of portb. this will end the mismatch condition. b) clear flag bit rbif. a mismatch condition will continue to set flag bit rbif. reading portb will end the mismatch condition and allow flag bit rbif to be cleared. the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. this interrupt on mismatch feature, together with soft- ware configurable pull-ups on these four pins, allow easy interface to a keypad and make it possible for wake-up on key depression. refer to the embedded control handbook, ?implementing wake-up on key stroke? (an552). rb0/int is an external interrupt input pin and is config- ured using the intedg bit (option_reg<6>). rb0/int is discussed in detail in section 11.10.1. figure 4-4: block diagram of rb7:rb4 pins data latch rbpu (2) p v dd q d ck q d ck qd en data bus wr port wr tris rd tris rd port weak pull-up rd port rb0/int i/o pin (1) ttl input buffer schmitt trigger buffer tris latch note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit (option_reg<7>). rb3/pgm data latch from other rbpu (2) p v dd i/o pin (1) q d ck q d ck qd en qd en data bus wr port wr tris set rbif tris latch rd tris rd port rb7:rb4 pins weak pull-up rd port latch ttl input buffer st buffer rb7:rb6 q3 q1 note 1: i/o pins have diode protection to v dd and v ss . 2: to enable weak pull-ups, set the appropriate tris bit(s) and clear the rbpu bit (option_reg<7>). in serial programming mode
pic16f872 ds30221c-page 32 ? 2006 microchip technology inc. table 4-3: portb functions table 4-4: summary of registers associated with portb name bit# buffer function rb0/int bit0 ttl/st (1) input/output pin or external interrupt input. internal software programmable weak pull-up. rb1 bit1 ttl input/output pin. internal software programmable weak pull-up. rb2 bit2 ttl input/output pin. internal software programmable weak pull-up. rb3/pgm bit3 ttl input/output pin or programming pin in lvp mode. internal software programmable weak pull-up. rb4 bit4 ttl input/output pin (with interrupt-on-change). internal software programmable weak pull-up. rb5 bit5 ttl input/output pin (with interrupt-on-change). internal software programmable weak pull-up. rb6/pgc bit6 ttl/st (2) input/output pin (with interrupt-on-change) or in-circuit debugger pin. internal software programmable weak pull-up. serial programming clock. rb7/pgd bit7 ttl/st (2) input/output pin (with interrupt-on-change) or in-circuit debugger pin. internal software programmable weak pull-up. serial programming data. legend: ttl = ttl input, st = schmitt trigger input note 1: this buffer is a schmitt trigger input when configured as the external interrupt. 2: this buffer is a schmitt trigger input when used in serial programming mode. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 06h, 106h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu 86h, 186h trisb portb data direction register 1111 1111 1111 1111 81h, 181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: x = unknown, u = unchanged. shaded cells are not used by portb.
? 2006 microchip technology inc. ds30221c-page 33 pic16f872 4.3 portc and the trisc register portc is an 8-bit wide, bi-directional port. the corre- sponding data direction register is trisc. setting a trisc bit (= ? 1 ?) will make the corresponding portc pin an input (i.e., put the corresponding output driver in a hi-impedance mode). clearing a trisc bit (= ? 0 ?) will make the corresponding portc pin an output (i.e., put the contents of the output latch on the selected pin). portc is multiplexed with several peripheral functions (table 4-5). portc pins have schmitt trigger input buffers. when the i 2 c module is enabled, the portc (4:3) pins can be configured with normal i 2 c levels or with smbus levels by using the cke bit (sspstat<6>). when enabling peripheral functions, care should be taken in defining tris bits for each portc pin. some peripherals override the tris bit to make a pin an out- put, while other peripherals override the tris bit to make a pin an input. since the tris bit override is in effect while the peripheral is enabled, read-modify- write instructions ( bsf, bcf, xorwf ) with trisc as the destination should be avoided. the user should refer to the corresponding peripheral section for the correct tris bit settings. figure 4-5: portc block diagram (peripheral output override) rc<2:0> rc<7:5> figure 4-6: portc block diagram (peripheral output override) rc<4:3> port/peripheral select (2) data bus wr port wr tris rd data latch tris latch rd schmitt trigger q d q ck qd en peripheral data out 0 1 q d q ck p n v dd v ss port peripheral oe (3) peripheral input i/o pin (1) note 1: i/o pins have diode protection to v dd and v ss . 2: port/peripheral select signal selects between port data and peripheral output. 3: peripheral oe (output enable) is only activated if peripheral select is active. tris port/peripheral select (2) data bus wr port wr tris rd data latch tris latch rd schmitt trigger q d q ck qd en peripheral data out 0 1 q d q ck p n v dd vss port peripheral oe (3) sspl input i/o pin (1) note 1: i/o pins have diode protection to v dd and v ss . 2: port/peripheral select signal selects between port data and peripheral output. 3: peripheral oe (output enable) is only activated if peripheral select is active. 0 1 cke sspstat<6> schmitt trigger with smbus levels tris
pic16f872 ds30221c-page 34 ? 2006 microchip technology inc. table 4-5: portc functions table 4-6: summary of registers associated with portc name bit# buffer type function rc0/t1oso/t1cki bit0 st input/output port pin or timer1 oscillator output/timer1 clock input. rc1/t1osi/ccp2 bit1 st input/output port pin or timer1 oscillator input or capture2 input/ compare2 output/pwm2 output. rc2/ccp1 bit2 st input/output port pin or capture1 input/compare1 output/ pwm output. rc3/sck/scl bit3 st rc3 can also be the synchronous serial clock for both spi and i 2 c modes. rc4/sdi/sda bit4 st rc4 can also be the spi data in (spi mode) or data i/o (i 2 c mode). rc5/sdo bit5 st input/output port pin or synchronous serial port data output (spi mode). rc6 bit6 st input/output port pin. rc7 bit7 st input/output port pin. legend: st = schmitt trigger input address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 07h portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 xxxx xxxx uuuu uuuu 87h trisc portc data direction register 1111 1111 1111 1111 legend: x = unknown, u = unchanged
? 2006 microchip technology inc. ds30221c-page 35 pic16f872 5.0 timer0 module the timer0 module timer/counter has the following features: ? 8-bit timer/counter ? readable and writable ? 8-bit software programmable prescaler ? internal or external clock select ? interrupt on overflow from ffh to 00h ? edge select for external clock figure 5-1 is a block diagram of the timer0 module and the prescaler shared with the wdt. additional information on the timer0 module is avail- able in the picmicro? mid-range mcu family refer- ence manual (ds33023). timer mode is selected by clearing bit t0cs (option_reg<5>). in timer mode, the timer0 mod- ule will increment every instruction cycle (without pres- caler). if the tmr0 register is written, the increment is inhibited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. counter mode is selected by setting bit t0cs (option_reg<5>). in counter mode, timer0 will increment either on every rising or falling edge of pin ra4/t0cki. the incrementing edge is determined by the timer0 source edge select bit t0se (option_reg<4>). clearing bit t0se selects the ris- ing edge. restrictions on the external clock input are discussed in detail in section 5.2. the prescaler is mutually exclusively shared between the timer0 module and the watchdog timer. the pres- caler is not readable or writable. section 5.3 details the operation of the prescaler. 5.1 timer0 interrupt the tmr0 interrupt is generated when the tmr0 reg- ister overflows from ffh to 00h. this overflow sets bit tmr0if (intcon<2>). the interrupt can be masked by clearing bit tmr0ie (intcon<5>). bit tmr0if must be cleared in software by the timer0 module interrupt service routine before re-enabling this inter- rupt. the tmr0 interrupt cannot awaken the processor from sleep, since the timer is shut-off during sleep. figure 5-1: block diagram of the timer0/wdt prescaler ra4/t0cki t0se pin m u x clkout (= f osc /4) sync 2 cycles tmr0 reg 8-bit prescaler 8 - to - 1mux m u x m u x watchdog timer psa 0 1 0 1 wdt time-out ps2:ps0 8 note: t0cs, t0se, psa, ps2:ps0 are (option_reg<5:0>). psa wdt enable bit m u x 0 1 0 1 data bus set flag bit tmr0if on overflow 8 psa t0cs prescaler
pic16f872 ds30221c-page 36 ? 2006 microchip technology inc. 5.2 using timer0 with an external clock when no prescaler is used, the external clock input is the same as the prescaler output. the synchronization of t0cki with the internal phase clocks is accom- plished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks. therefore, it is necessary for t0cki to be high for at least 2t osc (and a small rc delay of 20 ns) and low for at least 2t osc (and a small rc delay of 20 ns). refer to the electrical specification of the desired device. 5.3 prescaler there is only one prescaler available, which is mutually exclusively shared between the timer0 module and the watchdog timer. a prescaler assignment for the timer0 module means that there is no prescaler for the watchdog timer, and vice-versa. this prescaler is not readable or writable (see figure 5-1). the psa and ps2:ps0 bits (option_reg<3:0>) determine the prescaler assignment and prescale ratio. when assigned to the timer0 module, all instructions writing to the tmr0 register (e.g. clrf 1, movwf 1, bsf 1,x ....etc.) will clear the prescaler. when assigned to wdt, a clrwdt instruction will clear the prescaler along with the watchdog timer. the prescaler is not readable or writable. register 5-1: option_reg register note: writing to tmr0, when the prescaler is assigned to timer0, will clear the prescaler count, but will not change the prescaler assignment. r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 bit 7 rbpu bit 6 intedg bit 5 t0cs : tmr0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (clkout) bit 4 t0se : tmr0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa : prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps2:ps0 : prescaler rate select bits legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate note: to avoid an unintended device reset, the instruction sequence shown in the picmicro? mid-range mcu family reference manual (ds33023) must be executed when changing the prescaler assignment from timer0 to the wdt. this sequence must be followed even if the wdt is disabled.
? 2006 microchip technology inc. ds30221c-page 37 pic16f872 table 5-1: registers associated with timer0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 01h,101h tmr0 timer0 module register xxxx xxxx uuuu uuuu 0bh,8bh, 10bh,18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 81h,181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented locations read as '0'. shaded cells are not used by timer0.
pic16f872 ds30221c-page 38 ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. ds30221c-page 39 pic16f872 6.0 timer1 module the timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (tmr1h and tmr1l), which are readable and writable. the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the tmr1 interrupt, if enabled, is generated on overflow, which is latched in interrupt flag bit tmr1if (pir1<0>). this interrupt can be enabled/disabled by setting/clearing tmr1 interrupt enable bit tmr1ie (pie1<0>). timer1 can operate in one of two modes: ?as a timer ? as a counter the operating mode is determined by the clock select bit, tmr1cs (t1con<1>). in timer mode, timer1 increments every instruction cycle. in counter mode, it increments on every rising edge of the external clock input. timer1 can be enabled/disabled by setting/clearing control bit tmr1on (t1con<0>). timer1 also has an internal ?reset input?. this reset can be generated by either of the two ccp modules (section 8.0). register 6-1 shows the timer1 control register. when the timer1 oscillator is enabled (t1oscen is set), the rc1/t1osi/ccp2 and rc0/t1oso/t1cki pins become inputs. that is, the trisc<1:0> value is ignored, and these pins read as ?0?. additional information on timer modules is available in the picmicro? mid-range mcu family reference manual (ds33023). register 6-1: t1con: timer1 co ntrol register (address 10h) u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 bit 7-6 unimplemented: read as '0' bit 5-4 t1ckps1:t1ckps0 : timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen : timer1 oscillator enable control bit 1 = oscillator is enabled 0 = oscillator is shut off (the oscillator inverter is turned off to eliminate power drain) bit 2 t1sync : timer1 external clock input synchronization control bit when tmr1cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr1cs = 0 : this bit is ignored. timer1 uses the internal clock when tmr1cs = 0. bit 1 tmr1cs : timer1 clock source select bit 1 = external clock from pin rc0/t1oso/t1cki (on the rising edge) 0 = internal clock (f osc /4) bit 0 tmr1on : timer1 on bit 1 = enables timer1 0 = stops timer1 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f872 ds30221c-page 40 ? 2006 microchip technology inc. 6.1 timer1 operation in timer mode timer mode is selected by clearing the tmr1cs (t1con<1>) bit. in this mode, the input clock to the timer is f osc /4. the synchronize control bit t1sync (t1con<2>) has no effect since the internal clock is always in sync. 6.2 timer1 counter operation timer1 may operate in either a synchronous or an asynchronous mode, depending on the setting of the tmr1cs bit. when timer1 is being incremented via an external source, increments occur on a rising edge. after timer1 is enabled in counter mode, the module must first have a falling edge before the counter begins to increment. figure 6-1: timer1 incrementing edge 6.3 timer1 operation in synchronized counter mode counter mode is selected by setting bit tmr1cs. in this mode, the timer increments on every rising edge of clock input on pin rc1/t1osi/ccp2, when bit t1oscen is set, or on pin rc0/t1oso/t1cki, when bit t1oscen is cleared. if t1sync is cleared, then the external clock input is synchronized with internal phase clocks. the synchro- nization is done after the prescaler stage. the pres- caler stage is an asynchronous ripple counter. in this configuration, during sleep mode, timer1 will not increment even if the external clock is present, since the synchronization circuit is shut-off. the pres- caler, however, will continue to increment. figure 6-2: timer1 block diagram t1cki (default high) t1cki (default low) note: arrows indicate counter increments. tmr1h tmr1l t1osc t1sync tmr1cs t1ckps1:t1ckps0 q clock t1oscen enable oscillator (1) f osc /4 internal clock tmr1on on/off prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 rc0/t1oso/t1cki rc1/t1osi/ccp2 (2) note 1: when the t1oscen bit is cleared, the inverter is turned off. this eliminates power drain. set flag bit tmr1if on overflow tmr1
? 2006 microchip technology inc. ds30221c-page 41 pic16f872 6.4 timer1 operation in asynchronous counter mode if control bit t1sync (t1con<2>) is set, the external clock input is not synchronized. the timer continues to increment asynchronous to the internal phase clocks. the timer will continue to run during sleep and can generate an interrupt on overflow, which will wake-up the processor. however, special precautions in soft- ware are needed to read/write the timer (section 6.4.1). in asynchronous counter mode, timer1 cannot be used as a time-base for capture or compare opera- tions. 6.4.1 reading and writing timer1 in asynchronous counter mode reading tmr1h or tmr1l while the timer is running from an external asynchronous clock will guarantee a valid read (taken care of in hardware). however, the user should keep in mind that reading the 16-bit timer in two 8-bit values itself, poses certain problems, since the timer may overflow between the reads. for writes, it is recommended that the user simply stop the timer and write the desired values. a write conten- tion may occur by writing to the timer registers while the register is incrementing. this may produce an unpre- dictable value in the timer register. reading the 16-bit value requires some care. exam- ples 12-2 and 12-3 in the picmicro? mid-range mcu family reference manual (ds33023) show how to read and write timer1 when it is running in asynchro- nous mode. 6.5 timer1 oscillator a crystal oscillator circuit is built-in between pins t1osi (input) and t1oso (amplifier output). it is enabled by setting control bit t1oscen (t1con<3>). the oscilla- tor is a low power oscillator, rated up to 200 khz. it will continue to run during sleep. it is primarily intended for use with a 32 khz crystal. table 6-1 shows the capacitor selection for the timer1 oscillator. the timer1 oscillator is identical to the lp oscillator. the user must provide a software time delay to ensure proper oscillator start-up. table 6-1: capacitor selection for the timer1 oscillator 6.6 resetting timer1 using a ccp trigger output if the ccp1 or ccp2 module is configured in compare mode to generate a ?special event trigger? (ccp1m3:ccp1m0 = 1011 ), this signal will reset timer1. timer1 must be configured for either timer or synchro- nized counter mode to take advantage of this feature. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a spe- cial event trigger from ccp1 or ccp2, the write will take precedence. in this mode of operation, the ccprxh:ccprxl regis- ter pair effectively becomes the period register for timer1. 6.7 resetting of timer1 register pair (tmr1h, tmr1l) tmr1h and tmr1l registers are not reset to 00h on a por or any other reset, except by the ccp1 and ccp2 special event triggers. t1con register is reset to 00h on a power-on reset or a brown-out reset, which shuts off the timer and leaves a 1:1 prescale. in all other resets, the register is unaffected. 6.8 timer1 prescaler the prescaler counter is cleared on writes to the tmr1h or tmr1l registers. osc type freq c1 c2 lp 32 khz 33 pf 33 pf 100 khz 15 pf 15 pf 200 khz 15 pf 15 pf these values are for design guidance only. crystals tested: 32.768 khz epson c-001r32.768k-a 20 ppm 100 khz epson c-2 100.00 kc-p 20 ppm 200 khz std xtl 200.000 khz 20 ppm note 1: higher capacitance increases the stability of oscillator, but also increases the start-up time. 2: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appro- priate values of external components. note: the special event triggers from the ccp1 and ccp2 modules will not set interrupt flag bit tmr1if (pir1<0>).
pic16f872 ds30221c-page 42 ? 2006 microchip technology inc. table 6-2: registers associated with timer1 as a timer/counter address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 0ch pir1 (3) adif (3) (3) sspif ccp1if tmr2if tmr1if r0rr 0000 0000 0000 8ch pie1 (3) adie (3) (3) sspie ccp1ie tmr2ie tmr1ie r0rr 0000 0000 0000 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cell s are not used by the timer1 module.
? 2006 microchip technology inc. ds30221c-page 43 pic16f872 7.0 timer2 module timer2 is an 8-bit timer with a prescaler and a postscaler. it can be used as the pwm time-base for the pwm mode of the ccp module(s). the tmr2 reg- ister is readable and writable, and is cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits t2ckps1:t2ckps0 (t2con<1:0>). the timer2 module has an 8-bit period register, pr2. timer2 increments from 00h until it matches pr2 and then resets to 00h on the next increment cycle. pr2 is a readable and writable register. the pr2 register is initialized to ffh upon reset. the match output of tmr2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a tmr2 interrupt (latched in flag bit, tmr2if (pir1<1>)). timer2 can be shut-off by clearing control bit tmr2on (t2con<2>) to minimize power consumption. register 7-1 shows the timer2 control register. additional information on timer modules is available in the picmicro? mid-range mcu family reference manual (ds33023). figure 7-1: timer2 block diagram register 7-1: t2con: timer2 co ntrol register (address 12h) comparator tmr2 sets flag tmr2 reg output (1) reset postscaler prescaler pr2 reg 2 f osc /4 1:1 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if note 1: tmr2 register output can be software selected by the ssp module as a baud clock. to t2outps3: t2outps0 t2ckps1: t2ckps0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 bit 7 unimplemented: read as '0' bit 6-3 toutps3:toutps0 : timer2 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale 0010 = 1:3 postscale ? ? ? 1111 = 1:16 postscale bit 2 tmr2on : timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps1:t2ckps0 : timer2 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f872 ds30221c-page 44 ? 2006 microchip technology inc. 7.1 timer2 prescaler and postscaler the prescaler and postscaler counters are cleared when any of the following occurs: ? a write to the tmr2 register ? a write to the t2con register ? any device reset (por, mclr reset, wdt reset or bor) tmr2 is not cleared when t2con is written. 7.2 output of tmr2 the output of tmr2 (before the postscaler) is fed to the ssp module, which optionally uses it to generate shift clock. table 7-1: registers associated with timer2 as a timer/counter address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 0ch pir1 (3) adif (3) (3) sspif ccp1if tmr2if tmr1if r0rr 0000 0000 0000 8ch pie1 (3) adie (3) (3) sspie ccp1ie tmr2ie tmr1ie r0rr 0000 0000 0000 11h tmr2 timer2 module register 0000 0000 0000 0000 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 92h pr2 timer2 period register 1111 1111 1111 1111 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cell s are not used by the timer2 module.
? 2006 microchip technology inc. ds30221c-page 45 pic16f872 8.0 capture/compare/pwm module the capture/compare/pwm (ccp) module contains a 16-bit register, which can operate as a: ? 16-bit capture register ? 16-bit compare register ? pwm master/slave duty cycle register the timer resources used by the module are shown in table 8-1. capture/compare/pwm register 1 (ccpr1) is com- prised of two 8-bit registers: ccpr1l (low byte) and ccpr1h (high byte). the ccp1con register controls the operation of ccp1. the special event trigger is generated by a compare match and will reset timer1. additional information on ccp modules is available in the picmicro? mid-range mcu family reference manual (ds33023) and in application note (an594), ?using the ccp modules? (ds00594). table 8-1: ccp mode - timer resources required register 8-1: ccp1con register (address: 17h) ccp mode timer resource capture compare pwm timer1 timer1 timer2 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 bit 7-6 unimplemented: read as '0' bit 5-4 ccp1x:ccp1y : pwm least significant bits capture mode : unused compare mode: unused pwm mode: these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccpr1l. bit 3-0 ccp1m3:ccp1m0 : ccp1 mode select bits 0000 = capture/compare/pwm disabled (resets ccp module) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccp1if bit is set) 1001 = compare mode, clear output on match (ccp1if bit is set) 1010 = compare mode, generate software interrupt on match (ccp1if bit is set, ccp1 pin is unaffected) 1011 = compare mode, trigger special event (ccp1if bit is set, ccp1 pin is unaffected); ccp1 resets tmr1 and starts an a/d conversion (if a/d module is enabled) 11xx =pwm mode legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f872 ds30221c-page 46 ? 2006 microchip technology inc. 8.1 capture mode in capture mode, ccpr1h:ccpr1l captures the 16-bit value of the tmr1 register when an event occurs on pin rc2/ccp1. an event is defined as one of the following: ? every falling edge ? every rising edge ? every 4th rising edge ? every 16th rising edge the type of event is configured by control bits ccp1m3:ccp1m0 (ccp1con<3:0>). when a cap- ture is made, the interrupt request flag bit ccp1if (pir1<2>) is set. the interrupt flag must be cleared in software. if another capture occurs before the value in register ccpr1 is read, the old captured value is over- written by the new value. 8.1.1 ccp pin configuration in capture mode, the rc2/ccp1 pin should be config- ured as an input by setting the trisc<2> bit. figure 8-1: capture mode operation block diagram 8.1.2 timer1 mode selection timer1 must be running in timer mode or synchro- nized counter mode for the ccp module to use the capture feature. in asynchronous counter mode, the capture operation may not work. 8.1.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep bit ccp1ie (pie1<2>) clear to avoid false interrupts and should clear the flag bit, ccp1if, following any such change in operating mode. 8.1.4 ccp prescaler there are four prescaler settings, specified by bits ccp1m3:ccp1m0. whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared, therefore, the first capture may be from a non-zero prescaler. example 8-1 shows the recom- mended method for switching between capture pres- calers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 8-1: changing between capture prescalers note: if the rc2/ccp1 pin is configured as an output, a write to the port can cause a cap- ture condition. ccpr1h ccpr1l tmr1h tmr1l set flag bit ccp1if (pir1<2>) capture enable qs ccp1con<3:0> rc2/ccp1 prescaler 1, 4, 16 and edge detect pin clrf ccp1con ; turn ccp module off movlw new_capt_ps ; load the w reg with ; the new prescaler ; move value and ccp on movwf ccp1con ; load ccp1con with this ; value
? 2006 microchip technology inc. ds30221c-page 47 pic16f872 8.2 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against the tmr1 register pair value. when a match occurs, the rc2/ccp1 pin is: ? driven high ?driven low ? remains unchanged the action on the pin is based on the value of control bits, ccp1m3:ccp1m0 (ccp1con<3:0>). at the same time, interrupt flag bit ccp1if is set. figure 8-2: compare mode operation block diagram 8.2.1 ccp pin configuration the user must configure the rc2/ccp1 pin as an out- put by clearing the trisc<2> bit. 8.2.2 timer1 mode selection timer1 must be running in timer mode or synchro- nized counter mode if the ccp module is using the compare feature. in asynchronous counter mode, the compare operation may not work. 8.2.3 software interrupt mode when generate software interrupt mode is chosen, the ccp1 pin is not affected. the ccpif bit is set, causing a ccp interrupt (if enabled). 8.2.4 special event trigger in this mode, an internal hardware trigger is generated, which may be used to initiate an action. the special event trigger output of ccp1 resets the tmr1 register pair and starts an a/d conversion (if the a/d module is enabled). this allows the ccpr1 regis- ter to effectively be a 16-bit programmable period register for timer1. table 8-2: registers associated with capture, compare, and timer1 ccpr1h ccpr1l tmr1h tmr1l comparator qs r output logic special event trigger set flag bit ccp1if (pir1<2>) match rc2/ccp1 trisc<2> ccp1con<3:0> mode select output enable pin special event trigger will: reset timer1, but not set interrupt flag bit tmr1if (pir1<0>), and set bit go/done (adcon0<2>). note: clearing the ccp1con register will force the rc2/ccp1 compare output latch to the default low level. this is not the portc i/o data latch. note: the special event trigger from the ccp module will not set interrupt flag bit tmr1if (pir1<0>). address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 0ch pir1 (1) adif (1) (1) sspif ccp1if tmr2if tmr1if r0rr 0000 0000 0000 8ch pie1 (1) adie (1) (1) sspie ccp1ie tmr2ie tmr1ie r0rr 0000 0000 0000 87h trisc portc data direction register 1111 1111 1111 1111 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu 10h t1con ? ? t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on --00 0000 --uu uuuu 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cell s are not used by capture and timer1. note 1: these bits are reserved; always maintain clear.
pic16f872 ds30221c-page 48 ? 2006 microchip technology inc. 8.3 pwm mode (pwm) in pulse width modulation mode, the ccp1 pin pro- duces up to a 10-bit resolution pwm output. since the ccp1 pin is multiplexed with the portc data latch, the trisc<2> bit must be cleared to make the ccp1 pin an output. figure 8-3 shows a simplified block diagram of the ccp module in pwm mode. for a step-by-step procedure on how to set up the ccp module for pwm operation, see section 8.3.3. figure 8-3: simplified pwm block diagram a pwm output (figure 8-4) has a time-base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 8-4: pwm output 8.3.1 pwm period the pwm period is specified by writing to the pr2 reg- ister. the pwm period can be calculated using the fol- lowing formula: pwm period = [(pr2) + 1] ? 4 ? t osc ? (tmr2 prescale value) pwm frequency is defined as 1 / [pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: ?tmr2 is cleared ? the ccp1 pin is set (exception: if pwm duty cycle = 0%, the ccp1 pin will not be set) ? the pwm duty cycle is latched from ccpr1l into ccpr1h 8.3.2 pwm duty cycle the pwm duty cycle is specified by writing to the ccpr1l register and to the ccp1con<5:4> bits. up to 10-bit resolution is available. the ccpr1l contains the eight msbs and the ccp1con<5:4> contains the two lsbs. this 10-bit value is represented by ccpr1l:ccp1con<5:4>. the following equation is used to calculate the pwm duty cycle in time: p w m d u t y c y c l e = ( c c p r 1 l : c c p 1 c o n < 5 : 4 > ) ? t osc ? (tmr2 prescale value) ccpr1l and ccp1con<5:4> can be written to at any time, but the duty cycle value is not latched into ccpr1h until after a match between pr2 and tmr2 occurs (i.e., the period is complete). in pwm mode, ccpr1h is a read only register. the ccpr1h register and a 2-bit internal latch are used to double buffer the pwm duty cycle. this double buffering is essential for glitch-free pwm operation. when the ccpr1h and 2-bit latch match tmr2, con- catenated with an internal 2-bit q clock or 2 bits of the tmr2 prescaler, the ccp1 pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by the formula: note: clearing the ccp1con register will force the ccp1 pwm output latch to the default low level. this is not the portc i/o data latch. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (note 1) r q s duty cycle registers ccp1con<5:4> clear timer, ccp1 pin and latch d.c. trisc<2> rc2/ccp1 note 1: the 8-bit timer is concatenated with 2-bit internal q clock, or 2 bits of the prescaler to create 10-bit time-base. period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 note: the timer2 postscaler (see section 7.1) is not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. note: if the pwm duty cycle value is longer than the pwm period, the ccp1 pin will not be cleared. log ( f pwm log(2) f osc ) bits = resolution
? 2006 microchip technology inc. ds30221c-page 49 pic16f872 8.3.3 setup for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccpr1l register and ccp1con<5:4> bits. 3. make the ccp1 pin an output by clearing the trisc<2> bit. 4. set the tmr2 prescale value and enable timer2 by writing to t2con. 5. configure the ccp1 module for pwm operation. table 8-3: example pwm frequencies and resolutions at 20 mhz table 8-4: registers associated with pwm and timer2 pwm frequency 1.22 khz 4.88 khz 19.53 khz 78.12khz 156.3 khz 208.3 khz timer prescaler (1, 4, 16) 16 4 1 1 1 1 pr2 value ffh ffh ffh 3fh 1fh 17h maximum resolution (bits) 10 10 10 8 7 5.5 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh,8bh, 10bh, 18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 0ch pir1 (1) adif (1) (1) sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 8ch pie1 (1) adie (1) (1) sspie ccp1ie tmr2ie tmr1ie r0rr 0000 0000 0000 87h trisc portc data direction register 1111 1111 1111 1111 11h tmr2 timer2 modules register 0000 0000 0000 0000 92h pr2 timer2 module period register 1111 1111 1111 1111 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 15h ccpr1l capture/compare/pwm register1 (lsb) xxxx xxxx uuuu uuuu 16h ccpr1h capture/compare/pwm register1 (msb) xxxx xxxx uuuu uuuu 17h ccp1con ? ? ccp1x ccp1y ccp1m3 ccp1m2 ccp1m1 ccp1m0 --00 0000 --00 0000 legend: x = unknown, u = unchanged, - = unimplemented read as '0'. shaded ce lls are not used by pwm and timer2. note 1: these bits are reserved; always maintain clear.
pic16f872 ds30221c-page 50 ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. ds30221c-page 51 pic16f872 9.0 master synchronous serial port (mssp) module the master synchronous serial port (mssp) module is a serial interface useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial eeproms, shift registers, dis- play drivers, a/d converters, etc. the mssp module can operate in one of two modes: ? serial peripheral interface (spi) ? inter-integrated circuit (i 2 c) the operation of the module in spi mode is discussed in greater detail in section 9.1. the operations of the module in the the various i 2 c modes are covered in section 9.2, while special considerations for connect- ing the i 2 c bus are discussed in section 9.3. the mssp module is controlled by three special func- tion registers: ? sspstat ? sspcon ? sspcon2 the sspstat and sspcon registers are used in both spi and i 2 c modes; their individual bits take on differ- ent functions depending on the mode selected. the sspcon2 register, on the other hand, is associated only with i 2 c operations. the registers are detailed in registers 9-1 through 9-3 on the following pages.
pic16f872 ds30221c-page 52 ? 2006 microchip technology inc. register 9-1: sspstat: sync serial port status register (address: 94h) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 bit 7 smp : sample bit spi master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode in i 2 c master or slave mode: 1 = slew rate control disabled for standard speed mode (100 khz and 1 mhz) 0 = slew rate control enabled for high speed mode (400 khz) bit 6 cke : spi clock edge select bit (figure 9-2, figure 9-3 and figure 9-4) spi mode: for ckp = 0 1 = transmit happens on transition from active clock state to idle clock state 0 = transmit happens on transition from idle clock state to active clock state for ckp = 1 1 = data transmitted on falling edge of sck 0 = data transmitted on rising edge of sck in i 2 c master or slave mode: 1 = input levels conform to smbus spec 0 = input levels conform to i 2 c specs bit 5 d/a : data/address bit (i 2 c mode only) 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p : stop bit (i 2 c mode only. this bit is cleared when the mssp module is disabled, sspen is cleared.) 1 = indicates that a stop bit has been detected last (this bit is '0' on reset) 0 = stop bit was not detected last bit 3 s : start bit (i 2 c mode only. this bit is cleared when the mssp module is disabled, sspen is cleared.) 1 = indicates that a start bit has been detected last (this bit is '0' on reset) 0 = start bit was not detected last bit 2 r/w : read/write bit information (i 2 c mode only) this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or not ack bit. in i 2 c slave mode: 1 = read 0 = write in i 2 c master mode: 1 = transmit is in progress 0 = transmit is not in progress. logical or of this bit with sen, rsen, pen, rcen or acken will indicate if the mssp is in idle mode. bit 1 ua : update address bit (10-bit i 2 c mode only) 1 = indicates that the user needs to update the address in the sspadd register 0 = address does not need to be updated bit 0 bf : buffer full status bit receive (spi and i 2 c modes): 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty transmit (i 2 c mode only): 1 = data transmit in progress (does not include the ack and stop bits), sspbuf is full 0 = data transmit complete (does not include the ack and stop bits), sspbuf is empty legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2006 microchip technology inc. ds30221c-page 53 pic16f872 register 9-2: sspcon: sync serial port control register (address: 14h) r/w-0r/w-0r/w-0r/w-0r/w-0r/w-0r/w-0r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 bit 7 wcol : write collision detect bit master mode: 1 = a write to sspbuf was attempted while the i 2 c conditions were not valid 0 = no collision slave mode: 1 = sspbuf register is written while still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov : receive overflow indicator bit in spi mode: 1 = a new byte is received while sspbuf holds previous data. data in sspsr is lost on overflow. in slave mode, the user must read the sspbuf, even if only transmitting data, to avoid over- flows. in master mode, the overflow bit is not set since each operation is initiated by writing to the sspbuf register. (must be cleared in software.) 0 = no overflow in i 2 c mode: 1 = a byte is received while the sspbuf is holding the previous byte. sspov is a "don?t care" in transmit mode. (must be cleared in software.) 0 = no overflow bit 5 sspen : synchronous serial port enable bit in spi mode : when enabled, these pins must be properly configured as input or output. 1 = enables serial port and configures sck, sdo, sdi, and ss as the source of the serial port pins 0 = disables serial port and configures these pins as i/o port pins in i 2 c mode : when enabled, these pins must be properly configured as input or output. 1 = enables the serial port and configures the sda and scl pins as the source of the serial port pins 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp : clock polarity select bit in spi mode: 1 = idle state for clock is a high level 0 = idle state for clock is a low level in i 2 c slave mode : sck release control 1 = enable clock 0 = holds clock low (clock stretch). (used to ensure data setup time.) in i 2 c master mode: unused in this mode bit 3-0 sspm3:sspm0 : synchronous serial port mode select bits 0000 = spi master mode, clock = f osc /4 0001 = spi master mode, clock = f osc /16 0010 = spi master mode, clock = f osc /64 0011 = spi master mode, clock = tmr2 output/2 0100 = spi slave mode, clock = sck pin. ss pin control enabled. 0101 = spi slave mode, clock = sck pin. ss pin control disabled. ss can be used as i/o pin. 0110 =i 2 c slave mode, 7-bit address 0111 =i 2 c slave mode, 10-bit address 1000 =i 2 c master mode, clock = f osc / (4 * (sspadd+1) 1011 =i 2 c firmware controlled master mode (slave idle) 1110 =i 2 c firmware controlled master mode, 7-bit address with start and stop bit interrupts enabled 1111 =i 2 c firmware controlled master mode, 10-bit address with start and stop bit interrupts enabled 1001, 1010, 1100, 1101 = reserved legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f872 ds30221c-page 54 ? 2006 microchip technology inc. register 9-3: sspcon2: sync serial port control register2 (address: 91h) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt acken rcen pen rsen sen bit 7 bit 0 bit 7 gcen : general call enable bit (in i 2 c slave mode only) 1 = enable interrupt when a general call address (0000h) is received in the sspsr 0 = general call address disabled bit 6 ackstat : acknowledge status bit (in i 2 c master mode only) in master transmit mode: 1 = acknowledge was not received from slave 0 = acknowledge was received from slave bit 5 ackdt : acknowledge data bit (in i 2 c master mode only) in master receive mode: value that will be transmitted when the user initiates an acknowledge sequence at the end of a receive. 1 = not acknowledge 0 = acknowledge bit 4 acken : acknowledge sequence enable bit (in i 2 c master mode only) in master receive mode: 1 = initiate acknowledge sequence on sda and scl pins, and transmit ackdt data bit. auto- matically cleared by hardware. 0 = acknowledge sequence idle bit 3 rcen : receive enable bit (in i 2 c master mode only). 1 = enables receive mode for i 2 c 0 = receive idle bit 2 pen : stop condition enable bit (in i 2 c master mode only) sck release control: 1 = initiate stop condition on sda and scl pins. automatically cleared by hardware. 0 = stop condition idle bit 1 rsen : repeated start condition enabled bit (in i 2 c master mode only) 1 = initiate repeated start condition on sda and scl pins. automatically cleared by hardware. 0 = repeated start condition idle bit 0 sen : start condition enabled bit (in i 2 c master mode only) 1 = initiate start condition on sda and scl pins. automatically cleared by hardware. 0 = start condition idle note: for bits acken, rcen, pen, rsen, sen: if the i 2 c module is not in the idle mode, this bit may not be set (no spooling), and the sspbuf may not be written (or writes to the sspbuf are disabled). legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
? 2006 microchip technology inc. ds30221c-page 55 pic16f872 9.1 spi mode the spi mode allows 8 bits of data to be synchronously transmitted and received, simultaneously. all four modes of spi are supported. to accomplish communi- cation, typically three pins are used: ? serial data out (sdo) ? serial data in (sdi) ? serial clock (sck) additionally, a fourth pin may be used when in a slave mode of operation: ? slave select (ss ) when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits (sspcon<5:0> and sspstat<7:6>). these control bits allow the following to be specified: ? master mode (sck is the clock output) ? slave mode (sck is the clock input) ? clock polarity (idle state of sck) ? data input sample phase (middle or end of data output time) ? clock edge (output data on rising/falling edge of sck) ? clock rate (master mode only) ? slave select mode (slave mode only) figure 9-4 shows the block diagram of the mssp mod- ule when in spi mode. to enable the serial port, mssp enable bit, sspen (sspcon<5>) must be set. to reset or reconfigure spi mode, clear bit sspen, re-initialize the sspcon reg- isters, and then set bit sspen. this configures the sdi, sdo, sck and ss pins as serial port pins. for the pins to behave as the serial port function, some must have their data direction bits (in the tris register) appropriately programmed. that is: ? sdi is automatically controlled by the spi module ? sdo must have trisc<5> cleared ? sck (master mode) must have trisc<3> cleared ? sck (slave mode) must have trisc<3> set ?ss must have trisa<5> set, and ? register adcon1 must be set in a way that pin ra5 is configured as a digital i/o any serial port function that is not desired may be over- ridden by programming the corresponding data direc- tion (tris) register to the opposite value. figure 9-1: mssp block diagram (spi mode) 9.1.1 master mode the master can initiate the data transfer at any time because it controls the sck. the master determines when the slave (processor 2, figure 9-5) is to broad- cast data by the software protocol. in master mode, the data is transmitted/received as soon as the sspbuf register is written to. if the spi module is only going to receive, the sdo output could be disabled (programmed as an input). the sspsr register will continue to shift in the signal present on the sdi pin at the programmed clock rate. as each byte is received, it will be loaded into the sspbuf register as if a normal received byte (interrupts and status bits appropriately set). this could be useful in receiver applications as a ?line activity monitor?. read write internal data bus sspsr reg sspm3:sspm0 bit0 shift clock ss control enable edge select clock select tmr2 output t osc prescaler 4, 16, 64 2 edge select 2 4 data to tx/rx in sspsr data direction bit 2 smp:cke sdi sdo ss sck sspbuf reg
pic16f872 ds30221c-page 56 ? 2006 microchip technology inc. the clock polarity is selected by appropriately program- ming bit ckp (sspcon<4>). this, then, would give waveforms for spi communication as shown in figure 9-6, figure 9-8 and figure 9-9, where the msb is transmitted first. in master mode, the spi clock rate (bit rate) is user programmable to be one of the following: ?f osc /4 (or t cy ) ?f osc /16 (or 4 ? t cy ) ?f osc /64 (or 16 ? t cy ) ? timer2 output/2 this allows a maximum bit clock frequency (at 20 mhz) of 5.0 mhz. figure 9-6 shows the waveforms for master mode. when cke = 1, the sdo data is valid before there is a clock edge on sck. the change of the input sample is shown based on the state of the smp bit. the time when the sspbuf is loaded with the received data is shown. figure 9-2: spi mode timing, master mode 9.1.2 slave mode in slave mode, the data is transmitted and received as the external clock pulses appear on sck. when the last bit is latched, the interrupt flag bit sspif (pir1<3>) is set. while in slave mode, the external clock is supplied by the external clock source on the sck pin. this external clock must meet the minimum high and low times, as specified in the electrical specifications. while in sleep mode, the slave can transmit/receive data. when a byte is received, the device will wake-up from sleep. sck (ckp = 0, sdi (smp = 0) sspif bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sdi (smp = 1) sck (ckp = 0, sck (ckp = 1, sck (ckp = 1, sdo bit7 bit7 bit0 bit0 cke = 0) cke = 1) cke = 0) cke = 1) note 1: when the spi module is in slave mode with ss pin control enabled (sspcon<3:0> = 0100 ), the spi module will reset if the ss pin is set to v dd . 2: if the spi is used in slave mode with cke = '1', then ss pin control must be enabled.
? 2006 microchip technology inc. ds30221c-page 57 pic16f872 figure 9-3: spi mode timing (slave mode with cke = 0) figure 9-4: spi mode timing (slave mode with cke = 1) table 9-1: registers associated with spi operation sck (ckp = 0) sdi (smp = 0) sspif bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sck (ckp = 1) sdo bit7 bit0 ss (optional) sck (ckp = 0) sdi (smp = 0) sspif bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 sck (ckp = 1) sdo bit7 bit0 ss address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh, 18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 0ch pir1 (1) adif (1) (1) sspif ccp1if tmr2if tmr1if r0rr 0000 0000 0000 8ch pie1 (1) adie (1) (1) sspie ccp1ie tmr2ie tmr1ie r0rr 0000 0000 0000 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 94h sspstat smp cke d/a p s r/w ua bf 0000 0000 0000 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cells are not used by the ssp in spi mode. note 1: these bits are reserved; always maintain these bits clear.
pic16f872 ds30221c-page 58 ? 2006 microchip technology inc. 9.2 mssp i 2 c operation the mssp module in i 2 c mode, fully implements all master and slave functions (including general call sup- port) and provides interrupts on start and stop bits in hardware to determine a free bus (multi-master func- tion). the mssp module implements the standard mode specifications, as well as 7-bit and 10-bit addressing. refer to application note (an578), "use of the ssp module in the i 2 c multi-master environment." a "glitch" filter is on the scl and sda pins when the pin is an input. this filter operates in both the 100 khz and 400 khz modes. in the 100 khz mode, when these pins are an output, there is a slew rate control of the pin that is independent of device frequency. figure 9-5: i 2 c slave mode block diagram two pins are used for data transfer. these are the scl pin, which is the clock, and the sda pin, which is the data. the sda and scl pins are automatically config- ured when the i 2 c mode is enabled. the ssp module functions are enabled by setting ssp enable bit sspen (sspcon<5>). the mssp module has six registers for i 2 c operation. they are the: ? ssp control register (sspcon) ? ssp control register2 (sspcon2) ? ssp status register (sspstat) ? serial receive/transmit buffer (sspbuf) ? ssp shift register (sspsr) - not directly accessible ? ssp address register (sspadd) the sspcon register allows control of the i 2 c opera- tion. four mode selection bits (sspcon<3:0>) allow one of the following i 2 c modes to be selected: ?i 2 c slave mode (7-bit address) ?i 2 c slave mode (10-bit address) ?i 2 c master mode, clock = osc/4 (sspadd +1) before selecting any i 2 c mode, the scl and sda pins must be programmed to inputs by setting the appropri- ate tris bits. selecting an i 2 c mode by setting the sspen bit, enables the scl and sda pins to be used as the clock and data lines in i 2 c mode. pull-up resis- tors must be provided externally to the scl and sda pins for the proper operation of the i 2 c module. the cke bit (sspstat<6:7>) sets the levels of the sda and scl pins in either master or slave mode. when cke = 1, the levels will conform to the smbus specification. when cke = 0, the levels will conform to the i 2 c specification. the sspstat register gives the status of the data transfer. this information includes detection of a start (s) or stop (p) bit, specifies if the received byte was data or address, if the next byte is the com- pletion of 10-bit address, and if this will be a read or write data transfer. sspbuf is the register to which the transfer data is written to or read from. the sspsr register shifts the data in or out of the device. in receive operations, the sspbuf and sspsr create a doubled buffered receiver. this allows reception of the next byte to begin before reading the last byte of received data. when the complete byte is received, it is transferred to the sspbuf register and flag bit sspif is set. if another complete byte is received before the sspbuf register is read, a receiver overflow has occurred and bit sspov (sspcon<6>) is set and the byte in the sspsr is lost. the sspadd register holds the slave address. in 10-bit mode, the user needs to write the high byte of the address ( 1111 0 a9 a8 0 ). following the high byte address match, the low byte of the address needs to be loaded (a7:a0). 9.2.1 slave mode in slave mode, the scl and sda pins must be config- ured as inputs. the mssp module will override the input state with the output data when required (slave- transmitter). when an address is matched, or the data transfer after an address match is received, the hardware automati- cally will generate the acknowledge (ack ) pulse, and then load the sspbuf register with the received value currently in the sspsr register. read write sspsr reg match detect sspadd reg start and stop bit detect sspbuf reg internal data bus addr match set, reset s, p bits (sspstat reg) scl shift clock msb lsb sda
? 2006 microchip technology inc. ds30221c-page 59 pic16f872 there are certain conditions that will cause the mssp module not to give this ack pulse. these are if either (or both): a) the buffer full bit bf (sspstat<0>) was set before the transfer was received. b) the overflow bit sspov (sspcon<6>) was set before the transfer was received. if the bf bit is set, the sspsr register value is not loaded into the sspbuf, but bit sspif and sspov are set. table 9-2 shows what happens when a data trans- fer byte is received, given the status of bits bf and sspov. the shaded cells show the condition where user software did not properly clear the overflow condi- tion. flag bit bf is cleared by reading the sspbuf reg- ister, while bit sspov is cleared through software. the scl clock input must have a minimum high and low time for proper operation. the high and low times of the i 2 c specification, as well as the requirement of the mssp module, is shown in timing parameter #100 and parameter #101 of the electrical specifications. 9.2.1.1 addressing once the mssp module has been enabled, it waits for a start condition to occur. following the start con- dition, the 8-bits are shifted into the sspsr register. all incoming bits are sampled with the rising edge of the clock (scl) line. the value of register sspsr<7:1> is compared to the value of the sspadd register. the address is compared on the falling edge of the eighth clock (scl) pulse. if the addresses match, and the bf and sspov bits are clear, the following events occur: a) the sspsr register value is loaded into the sspbuf register on the falling edge of the 8th scl pulse. b) the buffer full bit, bf, is set on the falling edge of the 8th scl pulse. c) an ack pulse is generated. d) ssp interrupt flag bit, sspif (pir1<3>), is set (interrupt is generated if enabled) on the falling edge of the 9th scl pulse. in 10-bit address mode, two address bytes need to be received by the slave. the five most significant bits (msbs) of the first address byte specify if this is a 10-bit address. bit r/w (sspstat<2>) must specify a write, so the slave device will receive the second address byte. for a 10-bit address the first byte would equal ? 1111 0 a9 a8 0 ?, where a9 and a8 are the two msbs of the address. the sequence of events for a 10-bit address is as follows, with steps 7-9 for slave transmitter: 1. receive first (high) byte of address (bits sspif, bf and ua (sspstat<1>) are set). 2. update the sspadd register with the second (low) byte of address (clears bit ua and releases the scl line). 3. read the sspbuf register (clears bit bf) and clear flag bit sspif. 4. receive second (low) byte of address (bits sspif, bf and ua are set). 5. update the sspadd register with the first (high) byte of address. this will clear bit ua and release the scl line. 6. read the sspbuf register (clears bit bf) and clear flag bit sspif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits sspif and bf are set). 9. read the sspbuf register (clears bit bf) and clear flag bit sspif. 9.2.1.2 slave reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspstat register is cleared. the received address is loaded into the sspbuf register. when the address byte overflow condition exists, then no acknowledge (ack ) pulse is given. an overflow condition is defined as either bit bf (sspstat<0>) is set, or bit sspov (sspcon<6>) is set. this is an error condition due to user firmware. an ssp interrupt is generated for each data transfer byte. flag bit sspif (pir1<3>) must be cleared in soft- ware. the sspstat register is used to determine the status of the received byte. note: following the repeated start condition (step 7) in 10-bit mode, the user only needs to match the first 7-bit address. the user does not update the sspadd for the second half of the address. note: the sspbuf will be loaded if the sspov bit is set and the bf flag is cleared. if a read of the sspbuf was performed, but the user did not clear the state of the sspov bit before the next receive occurred, the ack is not sent and the sspbuf is updated.
pic16f872 ds30221c-page 60 ? 2006 microchip technology inc. table 9-2: data transfer received byte actions 9.2.1.3 slave transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspstat register is set. the received address is loaded into the sspbuf register. the ack pulse will be sent on the ninth bit, and the scl pin is held low. the transmit data must be loaded into the sspbuf register, which also loads the sspsr register. then the scl pin should be enabled by setting bit ckp (sspcon<4>). the master must monitor the scl pin prior to asserting another clock pulse. the slave devices may be holding off the master by stretching the clock. the eight data bits are shifted out on the falling edge of the scl input. this ensures that the sda sig- nal is valid during the scl high time (figure 9-7). an ssp interrupt is generated for each data transfer byte. the sspif flag bit must be cleared in software and the sspstat register is used to determine the sta- tus of the byte transfer. the sspif flag bit is set on the falling edge of the ninth clock pulse. as a slave-transmitter, the ack pulse from the master receiver is latched on the rising edge of the ninth scl input pulse. if the sda line is high (not ack ), then the data transfer is complete. when the not ack is latched by the slave, the slave logic is reset and the slave then monitors for another occurrence of the start bit. if the sda line was low (ack ), the transmit data must be loaded into the sspbuf register, which also loads the sspsr register. then, the scl pin should be enabled by setting the ckp bit. figure 9-6: i 2 c waveforms for reception (7-bit address) status bits as data transfer is received sspsr sspbuf generate ack pulse set bit sspif (ssp interrupt occurs if enabled) bf sspov 0 0 yes yes yes 1 0 no no yes 1 1 no no yes 0 1 yes no yes note: shaded cells show the conditions where the user software did not properly clear the overflow condition. p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 12 3 4 5 6 7 8 9 12 3 4 56 7 89 123 4 bus master terminates transfer bit sspov is set because the sspbuf register is still full cleared in software sspbuf register is read ack receiving data receiving data d0 d1 d2 d3 d4 d5 d6 d7 ack r/w =0 receiving address sspif bf (sspstat<0>) sspov (sspcon<6>) ack ack is not sent not
? 2006 microchip technology inc. ds30221c-page 61 pic16f872 figure 9-7: i 2 c waveforms for transmission (7-bit address) 9.2.2 general call address support the addressing procedure for the i 2 c bus is such that the first byte after the start condition usually deter- mines which device will be the slave addressed by the master. the exception is the general call address, which can address all devices. when this address is used, all devices should, in theory, respond with an acknowledge. the general call address is one of eight addresses reserved for specific purposes by the i 2 c protocol. it consists of all 0?s with r/w = 0. the general call address is recognized when the gen- eral call enable bit (gcen) is enabled (sspcon2<7> is set). following a start bit detect, 8-bits are shifted into sspsr and the address is compared against sspadd. it is also compared to the general call address and fixed in hardware. if the general call address matches, the sspsr is transferred to the sspbuf, the bf flag is set (eighth bit), and on the falling edge of the ninth bit (ack bit), the sspif flag is set. when the interrupt is serviced, the source for the inter- rupt can be checked by reading the contents of the sspbuf, to determine if the address was device spe- cific or a general call address. in 10-bit mode, the sspadd is required to be updated for the second half of the address to match, and the ua bit is set (sspstat<1>). if the general call address is sampled when gcen is set while the slave is config- ured in 10-bit address mode, then the second half of the address is not necessary, the ua bit will not be set, and the slave will begin receiving data after the acknowledge (figure 9-8). figure 9-8: slave mode general call address sequence (7 or 10-bit mode) sda scl sspif bf (sspstat<0>) ckp (sspcon<4>) a7 a6 a5 a4 a3 a2 a1 ack d7 d6 d5 d4 d3 d2 d1 d0 not ack transmitting data r/w = 1 receiving address 123456789 123456789 p cleared in software sspbuf is written in software from ssp interrupt service routine set bit after writing to sspbuf s data in sampled scl held low while cpu responds to sspif (the sspbuf must be written to before the ckp bit can be set) r/w = 0 sda scl s sspif bf sspov cleared in software sspbuf is read r/w = 0 ack general call address address is compared to general call address gcen receiving data ack 123456789123456789 d7 d6 d5 d4 d3 d2 d1 d0 after ack, set interrupt flag '0' '1' (sspstat<0>) (sspcon<6>) (sspcon2<7>)
pic16f872 ds30221c-page 62 ? 2006 microchip technology inc. 9.2.3 sleep operation while in sleep mode, the i 2 c module can receive addresses or data. when an address match or com- plete byte transfer occurs, wake the processor from sleep (if the ssp interrupt is enabled). 9.2.4 effects of a reset a reset disables the ssp module and terminates the current transfer. table 9-3: registers associated with i 2 c operation address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on: por, bor value on all other resets 0bh, 8bh, 10bh,18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 0ch pir1 (1) adif (1) (1) sspif ccp1if tmr2if tmr1if 0000 0000 0000 0000 8ch pie1 (1) adie (1) (1) sspie ccp1ie tmr2ie tmr1ie r0rr 0000 0000 0000 0dh pir2 ? (1) ? eeif bclif ? (1) ccp2if -r-0 0--0 -r-0 0--0 8dh pie2 ? (1) ? eeie bclie ? (1) ccp2ie -r-0 0--r -r-0 0--r 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu 14h sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 91h sspcon2 gcen ackstat ackdt acken rcen pen rsen sen 0000 0000 0000 0000 94h sspstat smp cke d/a psr/w ua bf 0000 0000 0000 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cells are not used by the ssp in i 2 c mode. note 1: these bits are reserved; always maintain these bits clear.
? 2006 microchip technology inc. ds30221c-page 63 pic16f872 9.2.5 master mode master mode of operation is supported by interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit is set, or the bus is idle, with both the s and p bits clear. in master mode, the scl and sda lines are manipu- lated by the mssp hardware. the following events will cause the ssp interrupt flag bit, sspif, to be set (an ssp interrupt will occur if enabled): ? start condition ? stop condition ? data transfer byte transmitted/received ? acknowledge transmit ? repeated start figure 9-9: ssp block diagram (i 2 c master mode) 9.2.6 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions allows the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when bit p (sspstat<4>) is set, or the bus is idle with both the s and p bits clear. when the bus is busy, enabling the ssp interrupt will gener- ate the interrupt when the stop condition occurs. in multi-master operation, the sda line must be moni- tored for arbitration to see if the signal level is the expected output level. this check is performed in hard- ware, with the result placed in the bclif bit. the states where arbitration can be lost are: ? address transfer ? data transfer ? a start condition ? a repeated start condition ? an acknowledge condition read write sspsr start bit, stop bit, sspbuf internal data bus set/reset, s, p, wcol (sspstat) shift clock msb lsb sda acknowledge generate scl scl in bus collision sda in receive enable clock cntl clock arbitrate/wcol detect (hold off clock source) sspadd<6:0> baud set sspif, bclif reset ackstat, pen (sspcon2) rate generator sspm3:sspm0, start bit detect, stop bit detect write collision detect clock arbitration state counter for end of xmit/rcv
pic16f872 ds30221c-page 64 ? 2006 microchip technology inc. 9.2.7 i 2 c master mode support master mode is enabled by setting and clearing the appropriate sspm bits in sspcon and by setting the sspen bit. once master mode is enabled, the user has six options. ? assert a start condition on sda and scl. ? assert a repeated start condition on sda and scl. ? write to the sspbuf register, initiating transmis- sion of data/address. ? generate a stop condition on sda and scl. ? configure the i 2 c port to receive data. ? generate an acknowledge condition at the end of a received byte of data. 9.2.7.1 i 2 c master mode operation the master device generates all of the serial clock pulses and the start and stop conditions. a trans- fer is ended with a stop condition or with a repeated start condition. since the repeated start condi- tion is also the beginning of the next serial transfer, the i 2 c bus will not be released. in master transmitter mode, serial data is output through sda, while scl outputs the serial clock. the first byte transmitted contains the slave address of the receiving device (7 bits) and the read/write (r/w ) bit. in this case, the r/w bit will be logic '0'. serial data is transmitted 8 bits at a time. after each byte is transmit- ted, an acknowledge bit is received. start and stop conditions are output to indicate the beginning and the end of a serial transfer. in master receive mode, the first byte transmitted con- tains the slave address of the transmitting device (7 bits) and the r/w bit. in this case, the r/w bit will be logic '1'. thus, the first byte transmitted is a 7-bit slave address followed by a '1' to indicate receive bit. serial data is received via sda, while scl outputs the serial clock. serial data is received 8 bits at a time. after each byte is received, an acknowledge bit is transmitted. start and stop conditions indicate the beginning and end of transmission. the baud rate generator used for spi mode operation is now used to set the scl clock frequency for either 100 khz, 400 khz or 1 mhz i 2 c operation. the baud rate generator reload value is contained in the lower 7 bits of the sspadd register. the baud rate generator will automatically begin counting on a write to the sspbuf. once the given operation is complete (i.e., transmission of the last data bit is followed by ack) the internal clock will automatically stop counting and the scl pin will remain in its last state a typical transmit sequence would go as follows: a) the user generates a start condition by setting the start enable bit (sen) in sspcon2. b) sspif is set. the module will wait the required start time before any other operation takes place. c) the user loads the sspbuf with address to transmit. d) address is shifted out the sda pin until all 8 bits are transmitted. e) the mssp module shifts in the ack bit from the slave device and writes its value into the sspcon2 register (sspcon2<6>). f) the module generates an interrupt at the end of the ninth clock cycle by setting sspif. g) the user loads the sspbuf with eight bits of data. h) data is shifted out the sda pin until all 8 bits are transmitted. i) the mssp module shifts in the ack bit from the slave device, and writes its value into the sspcon2 register (sspcon2<6>). j) the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. k) the user generates a stop condition by setting the stop enable bit pen in sspcon2. l) interrupt is generated once the stop condition is complete. 9.2.8 baud rate generator in i 2 c master mode, the reload value for the brg is located in the lower 7 bits of the sspadd register (figure 9-10). when the brg is loaded with this value, the brg counts down to 0 and stops until another reload has taken place. the brg count is decremented twice per instruction cycle (t cy ), on the q2 and q4 clock. in i 2 c master mode, the brg is reloaded automatically. if clock arbitration is taking place, for instance, the brg will be reloaded when the scl pin is sampled high (figure 9-11). figure 9-10: baud rate generator block diagram note: the mssp module, when configured in i 2 c master mode, does not allow queueing of events. for instance, the user is not allowed to initiate a start condition and immediately write the sspbuf register to initiate transmission, before the start condition is complete. in this case, the sspbuf will not be written to and the wcol bit will be set, indicating that a write to the sspbuf did not occur. sspm3:sspm0 brg down counter clkout f osc /4 sspadd<6:0> sspm3:sspm0 scl reload control reload
? 2006 microchip technology inc. ds30221c-page 65 pic16f872 figure 9-11: baud rate generator timing with clock arbitration 9.2.9 i 2 c master mode start condition timing to initiate a start condition, the user sets the start condition enable bit, sen (sspcon2<0>). if the sda and scl pins are sampled high, the baud rate genera- tor is reloaded with the contents of sspadd<6:0> and starts its count. if scl and sda are both sampled high when the baud rate generator times out (t brg ), the sda pin is driven low. the action of the sda being driven low while scl is high is the start condition, and causes the s bit (sspstat<3>) to be set. follow- ing this, the baud rate generator is reloaded with the contents of sspadd<6:0> and resumes its count. when the baud rate generator times out (t brg ), the sen bit (sspcon2<0>) will be automatically cleared by hardware. the baud rate generator is suspended, leaving the sda line held low, and the start condition is complete. 9.2.9.1 wcol status flag if the user writes the sspbuf when a start sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 9-12: first start bit timing sda scl scl de-asserted but slave holds dx-1 dx brg scl is sampled high, reload takes place, and brg starts its count. 03h 02h 01h 00h (hold off) 03h 02h reload brg value scl low (clock arbitration) scl allowed to transition high brg decrements (on q2 and q4 cycles) note: if, at the beginning of start condition, the sda and scl pins are already sampled low, or if during the start condition, the scl line is sampled low before the sda line is driven low, a bus collision occurs, the bus collision interrupt flag (bclif) is set, the start condition is aborted, and the i 2 c module is reset into its idle state. note: because queueing of events is not allowed, writing to the lower 5 bits of sspcon2 is disabled until the start condition is complete. sda scl s t brg 1st bit 2nd bit t brg sda = 1, at completion of start bit, scl = 1 write to sspbuf occurs here t brg hardware clears sen bit t brg write to sen bit occurs here set s bit (sspstat<3>) and sets sspif bit
pic16f872 ds30221c-page 66 ? 2006 microchip technology inc. 9.2.10 i 2 c master mode repeated start condition timing a repeated start condition occurs when the rsen bit (sspcon2<1>) is programmed high and the i 2 c module is in the idle state. when the rsen bit is set, the scl pin is asserted low. when the scl pin is sam- pled low, the baud rate generator is loaded with the contents of sspadd<6:0> and begins counting. the sda pin is released (brought high) for one baud rate generator count (t brg ). when the baud rate generator times out if sda is sampled high, the scl pin will be de-asserted (brought high). when scl is sampled high, the baud rate generator is reloaded with the con- tents of sspadd<6:0> and begins counting. sda and scl must be sampled high for one t brg . this action is then followed by assertion of the sda pin (sda is low) for one t brg , while scl is high. following this, the rsen bit in the sspcon2 register will be automati- cally cleared and the baud rate generator will not be reloaded, leaving the sda pin held low. as soon as a start condition is detected on the sda and scl pins, the s bit (sspstat<3>) will be set. the sspif bit will not be set until the baud rate generator has timed out. immediately following the sspif bit getting set, the user may write the sspbuf with the 7-bit address in 7-bit mode, or the default first address in 10-bit mode. after the first eight bits are transmitted and an ack is received, the user may then transmit an additional eight bits of address (10-bit mode), or eight bits of data (7-bit mode). 9.2.10.1 wcol status flag if the user writes the sspbuf when a repeated start sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 9-13: repeat start condition waveform note 1: if rsen is programmed while any other event is in progress, it will not take effect. 2: a bus collision during the repeated start condition occurs if: ? sda is sampled low when scl goes from low to high. ? scl goes low before sda is asserted low. this may indicate that another master is attempting to transmit a data "1". note: because queueing of events is not allowed, writing of the lower 5 bits of sspcon2 is disabled until the repeated start condition is complete. sda scl sr = repeated start write to sspcon2 write to sspbuf occurs here falling edge of ninth clock end of xmit at completion of start bit, hardware clear rsen bit 1st bit set s (sspstat<3>) t brg t brg sda = 1, sda = 1, scl(no change). scl = 1 occurs here. t brg t brg t brg and set sspif
? 2006 microchip technology inc. ds30221c-page 67 pic16f872 9.2.11 i 2 c master mode transmission transmission of a data byte, a 7-bit address, or either half of a 10-bit address, is accomplished by simply writ- ing a value to sspbuf register. this action will set the buffer full flag (bf) and allow the baud rate generator to begin counting and start the next transmission. each bit of address/data will be shifted out onto the sda pin after the falling edge of scl is asserted (see data hold time spec). scl is held low for one baud rate gener- ator rollover count (t brg ). data should be valid before scl is released high (see data setup time spec). when the scl pin is released high, it is held that way for t brg . the data on the sda pin must remain stable for that duration and some hold time after the next falling edge of scl. after the eighth bit is shifted out (the fall- ing edge of the eighth clock), the bf flag is cleared and the master releases sda, allowing the slave device being addressed to respond with an ack bit during the ninth bit time, if an address match occurs or if data was received properly. the status of ack is read into the ackdt on the falling edge of the ninth clock. if the master receives an acknowledge, the acknowledge status bit (ackstat) is cleared. if not, the bit is set. after the ninth clock, the sspif is set and the master clock (baud rate generator) is suspended until the next data byte is loaded into the sspbuf, leaving scl low and sda unchanged (figure 9-14). after the write to the sspbuf, each bit of address will be shifted out on the falling edge of scl, until all seven address bits and the r/w bit are completed. on the fall- ing edge of the eighth clock, the master will de-assert the sda pin allowing the slave to respond with an acknowledge. on the falling edge of the ninth clock, the master will sample the sda pin to see if the address was recognized by a slave. the status of the ack bit is loaded into the ackstat status bit (sspcon2<6>). following the falling edge of the ninth clock transmis- sion of the address, the sspif is set, the bf flag is cleared, and the baud rate generator is turned off until another write to the sspbuf takes place, holding scl low and allowing sda to float. 9.2.11.1 bf status flag in transmit mode, the bf bit (sspstat<0>) is set when the cpu writes to sspbuf and is cleared when all 8 bits are shifted out. 9.2.11.2 wcol status flag if the user writes the sspbuf when a transmit is already in progress (i.e., sspsr is still shifting out a data byte), then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). wcol must be cleared in software. 9.2.11.3 ackstat status flag in transmit mode, the ackstat bit (sspcon2<6>) is cleared when the slave has sent an acknowledge (ack = 0), and is set when the slave does not acknowledge (ack = 1). a slave sends an acknowl- edge when it has recognized its address (including a general call), or when the slave has properly received its data.
pic16f872 ds30221c-page 68 ? 2006 microchip technology inc. figure 9-14: i 2 c master mode timing (transmission, 7 or 10-bit address) sda scl sspif bf (sspstat<0>) sen a7 a6 a5 a4 a3 a2 a1 ack = 0 d7d6d5d4d3d2d1d0 ack transmitting data or second half r/w = 0 transmit address to slave 123456789 123456789 p cleared in software service routine sspbuf is written in software from ssp interrupt after start condition sen cleared by hardware s sspbuf written with 7-bit address and r/w , start transmit scl held low while cpu responds to sspif sen = 0 of 10-bit address write sspcon2<0> sen = 1, start condition begins from slave, clear ackstat bit sspcon2<6> ackstat in sspcon2 = 1 cleared in software sspbuf written pen cleared in software r/w
? 2006 microchip technology inc. ds30221c-page 69 pic16f872 9.2.12 i 2 c master mode reception master mode reception is enabled by programming the receive enable bit, rcen (sspcon2<3>). the baud rate generator begins counting, and on each rollover, the state of the scl pin changes (high to low/ low to high), and data is shifted into the sspsr. after the falling edge of the eighth clock, the receive enable flag is automatically cleared, the contents of the sspsr are loaded into the sspbuf, the bf flag is set, the sspif is set, and the baud rate generator is sus- pended from counting, holding scl low. the ssp is now in idle state, awaiting the next command. when the buffer is read by the cpu, the bf flag is automati- cally cleared. the user can then send an acknowledge bit at the end of reception, by setting the acknowledge sequence enable bit, acken (sspcon2<4>). 9.2.12.1 bf status flag in receive operation, bf is set when an address or data byte is loaded into sspbuf from sspsr. it is cleared when sspbuf is read. 9.2.12.2 sspov status flag in receive operation, sspov is set when 8 bits are received into the sspsr, and the bf flag is already set from a previous reception. 9.2.12.3 wcol status flag if the user writes the sspbuf when a receive is already in progress (i.e., sspsr is still shifting in a data byte), then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). note: the ssp module must be in an idle state before the rcen bit is set, or the rcen bit will be disregarded.
pic16f872 ds30221c-page 70 ? 2006 microchip technology inc. figure 9-15: i 2 c master mode timing (reception, 7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 12 3 4 5 6 7 8 9 12 3 4 5 678 9 1234 bus master terminates transfer ack receiving data from slave receiving data from slave d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 1 transmit address to slave sspif bf ack is not sent write to sspcon2<0> (sen = 1), write to sspbuf occurs here ack from slave master configured as a receiver by programming sspcon2<3> (rcen = 1) pen bit = 1 written here data shifted in on falling edge of clk cleared in software start xmit sen = 0 sspov sda = 0, scl = 1, while cpu (sspstat<0>) ack last bit is shifted into sspsr and contents are unloaded into sspbuf cleared in software cleared in software set sspif interrupt at end of receive set p bit (sspstat<4>) and sspif cleared in software ack from master set sspif at end set sspif interrupt at end of acknowledge sequence set sspif interrupt at end of acknow- ledge sequence of receive set acken, start acknowledge sequence sspov is set because sspbuf is still full sda = ackdt = 1 rcen cleared automatically rcen = 1, start next receive write to sspcon2<4> to start acknowledge sequence sda = ackdt (sspcon2<5>) = 0 rcen cleared automatically responds to sspif acken begin start condition cleared in software sda = ackdt = 0
? 2006 microchip technology inc. ds30221c-page 71 pic16f872 9.2.13 acknowledge sequence timing an acknowledge sequence is enabled by setting the acknowledge sequence enable bit, acken (sspcon2<4>). when this bit is set, the scl pin is pulled low and the contents of the acknowledge data bit are presented on the sda pin. if the user wishes to gen- erate an acknowledge, the ackdt bit should be cleared. if not, the user should set the ackdt bit before starting an acknowledge sequence. the baud rate gen- erator then counts for one rollover period (t brg ), and the scl pin is de-asserted high). when the scl pin is sampled high (clock arbitration), the baud rate genera- tor counts for t brg . the scl pin is then pulled low. fol- lowing this, the acken bit is automatically cleared, the baud rate generator is turned off, and the ssp module then goes into idle mode (figure 9-16). 9.2.13.1 wcol status flag if the user writes the sspbuf when an acknowledge sequence is in progress, the wcol is set and the con- tents of the buffer are unchanged (the write doesn?t occur). figure 9-16: acknowledge sequence waveform 9.2.14 stop condition timing a stop bit is asserted on the sda pin at the end of a receive/transmit, by setting the stop sequence enable bit pen (sspcon2<2>). at the end of a receive/ transmit, the scl line is held low after the falling edge of the ninth clock. when the pen bit is set, the master will assert the sda line low. when the sda line is sam- pled low, the baud rate generator is reloaded and counts down to 0. when the baud rate generator times out, the scl pin will be brought high, and one t brg (baud rate generator rollover count) later, the sda pin will be de-asserted. when the sda pin is sampled high while scl is high, the p bit (sspstat<4>) is set. a t brg later, the pen bit is cleared and the sspif bit is set (figure 9-17). whenever the firmware decides to take control of the bus, it will first determine if the bus is busy by checking the s and p bits in the sspstat register. if the bus is busy, then the cpu can be interrupted (notified) when a stop bit is detected (i.e., bus is free). 9.2.14.1 wcol status flag if the user writes the sspbuf when a stop sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). note: t brg = one baud rate generator period. sda scl set sspif at the end acknowledge sequence starts here. write to sspcon2, acken automatically cleared cleared in t brg t brg of receive ack 8 acken = 1, ackdt = 0 d0 9 sspif software set sspif at the end of acknowledge sequence cleared in software
pic16f872 ds30221c-page 72 ? 2006 microchip technology inc. figure 9-17: stop condition receiv e or transmit mode 9.2.15 clock arbitration clock arbitration occurs when the master, during any receive, transmit, or repeated start/stop condi- tion, de-asserts the scl pin (scl allowed to float high). when the scl pin is allowed to float high, the baud rate generator (brg) is suspended from counting until the scl pin is actually sampled high. when the scl pin is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins counting. this ensures that the scl high time will always be at least one brg rollover count, in the event that the clock is held low by an external device (figure 9-18). 9.2.16 sleep operation while in sleep mode, the i 2 c module can receive addresses or data, and when an address match or complete byte transfer occurs, wake the processor from sleep (if the ssp interrupt is enabled). 9.2.17 effects of a reset a reset disables the ssp module and terminates the current transfer. figure 9-18: clock arbitrat ion timing in master transmit mode scl sda sda asserted low before rising edge of clock write to sspcon2, set pen falling edge of scl = 1 for t brg , followed by sda = 1 for t brg 9th clock scl brought high after t brg note: t brg = one baud rate generator period. t brg t brg after sda sampled high. p bit (sspstat<4>) is set. t brg to setup stop condition. ack p t brg pen bit (sspcon2<2>) is cleared by hardware and the sspif bit is set scl sda brg overflow, release scl. if scl = 1, load brg with sspadd<6:0> and start count brg overflow occurs, release scl. slave device holds scl low. scl = 1, brg starts counting clock high interval scl line sampled once every machine cycle (t osc ? 4). hold off brg until scl is sampled high. t brg t brg t brg to measure high time interval.
? 2006 microchip technology inc. ds30221c-page 73 pic16f872 9.2.18 multi -master communication, bus collision, and bus arbitration multi-master mode support is achieved by bus arbitra- tion. when the master outputs address/data bits onto the sda pin, arbitration takes place when the master outputs a '1' on sda, by letting sda float high and another master asserts a '0'. when the scl pin floats high, data should be stable. if the expected data on sda is a '1' and the data sampled on the sda pin = '0', a bus collision has taken place. the master will set the bus collision interrupt flag, bclif and reset the i 2 c port to its idle state. (figure 9-19). if a transmit was in progress when the bus collision occurred, the transmission is halted, the bf flag is cleared, the sda and scl lines are de-asserted, and the sspbuf can be written to. when the user services the bus collision interrupt service routine, and if the i 2 c bus is free, the user can resume communication by asserting a start condition. if a start, repeated start, stop or acknowledge condition was in progress when the bus collision occurred, the condition is aborted, the sda and scl lines are de-asserted, and the respective control bits in the sspcon2 register are cleared. when the user ser- vices the bus collision interrupt service routine, and if the i 2 c bus is free, the user can resume communication by asserting a start condition. the master will continue to monitor the sda and scl pins, and if a stop condition occurs, the sspif bit will be set. a write to the sspbuf will start the transmission of data at the first data bit, regardless of where the trans- mitter left off when the bus collision occurred. in multi-master mode, the interrupt generation on the detection of start and stop conditions allows the determination of when the bus is free. control of the i 2 c bus can be taken when the p bit is set in the sspstat register, or the bus is idle and the s and p bits are cleared. figure 9-19: bus collision timing for transmit and acknowledge sda scl bclif sda released sda line pulled low by another source sample sda. while scl is high, data doesn?t match what is driven bus collision has occurred. set bus collision interrupt by the master. by master data changes while scl = 0
pic16f872 ds30221c-page 74 ? 2006 microchip technology inc. 9.2.18.1 bus collision during a start condition during a start condition, a bus collision occurs if: a) sda or scl are sampled low at the beginning of the start condition (figure 9-20). b) scl is sampled low before sda is asserted low. (figure 9-21). during a start condition, both the sda and the scl pins are monitored. if either the sda pin or the scl pin is already low, then these events all occur: ? the start condition is aborted, ?and the bclif flag is set ?and the ssp module is reset to its idle state (figure 9-20). the start condition begins with the sda and scl pins de-asserted. when the sda pin is sampled high, the baud rate generator is loaded from sspadd<6:0> and counts down to 0. if the scl pin is sampled low while sda is high, a bus collision occurs, because it is assumed that another master is attempting to drive a data '1' during the start condition. if the sda pin is sampled low during this count, the brg is reset and the sda line is asserted early (figure 9-22). if, however, a '1' is sampled on the sda pin, the sda pin is asserted low at the end of the brg count. the baud rate generator is then reloaded and counts down to 0. during this time, if the scl pins are sampled as '0', a bus collision does not occur. at the end of the brg count, the scl pin is asserted low. figure 9-20: bus collision during st art condition (sda only) note: the reason that bus collision is not a factor during a start condition, is that no two bus masters can assert a start condition at the exact same time. therefore, one master will always assert sda before the other. this condition does not cause a bus collision, because the two masters must be allowed to arbitrate the first address follow- ing the start condition. if the address is the same, arbitration must be allowed to continue into the data portion, repeated start or stop conditions. sda scl sen sda sampled low before sda goes low before the sen bit is set. s bit and sspif set because ssp module reset into idle state. sen cleared automatically because of bus collision. s bit and sspif set because set sen, enable start condition if sda = 1, scl=1 sda = 0, scl = 1. bclif s sspif sda = 0, scl = 1. sspif and bclif are cleared in software sspif and bclif are cleared in software set bclif, set bclif. start condition.
? 2006 microchip technology inc. ds30221c-page 75 pic16f872 figure 9-21: bus collision during st art condition (scl = 0) figure 9-22: brg reset due to sda collisio n during start condition sda scl sen bus collision occurs. set bclif. scl = 0 before sda = 0, set sen, enable start sequence if sda = 1, scl = 1 t brg t brg sda = 0, scl = 1 bclif s sspif interrupts cleared in software bus collision occurs. set bclif. scl = 0 before brg time-out, '0' '0' '0' '0' sda scl sen set s set sen, enable start sequence if sda = 1, scl = 1 less than t brg t brg sda = 0, scl = 1 bclif s sspif s interrupts cleared in software. set sspif sda = 0, scl = 1 sda pulled low by other master. reset brg and assert sda. scl pulled low after brg time-out set sspif '0'
pic16f872 ds30221c-page 76 ? 2006 microchip technology inc. 9.2.18.2 bus collision during a repeated start condition during a repeated start condition, a bus collision occurs if: a) a low level is sampled on sda when scl goes from low level to high level. b) scl goes low before sda is asserted low, indi- cating that another master is attempting to trans- mit a data ?1?. when the user de-asserts sda and the pin is allowed to float high, the brg is loaded with sspadd<6:0> and counts down to 0. the scl pin is then de-asserted, and when sampled high, the sda pin is sampled. if sda is low, a bus collision has occurred (i.e., another master is attempting to transmit a data?0?). if, however, sda is sampled high, the brg is reloaded and begins counting. if sda goes from high to low before the brg times out, no bus collision occurs, because no two masters can assert sda at exactly the same time. if, however, scl goes from high to low before the brg times out and sda has not already been asserted, a bus collision occurs. in this case, another master is attempting to transmit a data?1? during the repeated start condition. if, at the end of the brg time-out, both scl and sda are still high, the sda pin is driven low, the brg is reloaded and begins counting. at the end of the count, regardless of the status of the scl pin, the scl pin is driven low and the repeated start condition is com- plete (figure 9-23). figure 9-23: bus collision during a repeated start condition (case 1) figure 9-24: bus collision during repeat ed start condition (case 2) sda scl rsen bclif s sspif sample sda when scl goes high. if sda = 0, set bclif and release sda and scl. cleared in software '0' '0' '0' '0' sda scl bclif rsen s sspif interrupt cleared in software scl goes low before sda, set bclif. release sda and scl. t brg t brg '0' '0' '0' '0'
? 2006 microchip technology inc. ds30221c-page 77 pic16f872 9.2.18.3 bus collision during a stop condition bus collision occurs during a stop condition if: a) after the sda pin has been de-asserted and allowed to float high, sda is sampled low after the brg has timed out. b) after the scl pin is de-asserted, scl is sam- pled low before sda goes high. the stop condition begins with sda asserted low. when sda is sampled low, the scl pin is allowed to float. when the pin is sampled high (clock arbitration), the baud rate generator is loaded with sspadd<6:0> and counts down to 0. after the brg times out, sda is sampled. if sda is sampled low, a bus collision has occurred. this is due to another master attempting to drive a data '0'. if the scl pin is sampled low before sda is allowed to float high, a bus collision occurs. this is a case of another master attempting to drive a data '0' (figure 9-25). figure 9-25: bus collision during a stop condition (case 1) figure 9-26: bus collision during a stop condition (case 2) sda scl bclif pen p sspif t brg t brg t brg sda asserted low sda sampled low after t brg , set bclif '0' '0' '0' '0' sda scl bclif pen p sspif t brg t brg t brg assert sda scl goes low before sda goes high, set bclif '0' '0'
pic16f872 ds30221c-page 78 ? 2006 microchip technology inc. 9.3 connection considerations for i 2 c bus for standard mode i 2 c bus devices, the values of resistors r p and r s in figure 9-27 depend on the fol- lowing parameters: ? supply voltage ? bus capacitance ? number of connected devices (input current + leakage current). the supply voltage limits the minimum value of resistor r p , due to the specified minimum sink current of 3 ma at v ol max = 0.4v, for the specified output stages. for example, with a supply voltage of v dd = 5v+ 10% and v ol max = 0.4v at 3 ma, r p min = (5.5-0.4)/0.003 = 1.7 k . v dd , as a function of r p , is shown in figure 9-27. the desired noise margin of 0.1 v dd for the low level limits the maximum value of r s . series resistors are optional and used to improve esd susceptibility. the bus capacitance is the total capacitance of wire, connections, and pins. this capacitance limits the max- imum value of r p , due to the specified rise time (figure 9-27). the smp bit is the slew rate control enabled bit. this bit is in the sspstat register, and controls the slew rate of the i/o pins when in i 2 c mode (master or slave). figure 9-27: sample device configuration for i 2 c bus rp rp v dd + 10% sda scl device c b =10 - 400 pf rs rs note: i 2 c devices with input levels related to v dd must have one common supply line to which the pull-up resistor is also connected.
? 2006 microchip technology inc. ds30221c-page 79 pic16f872 10.0 analog-to-digital converter (a/d) module the analog-to-digital (a/d) converter module has five input channels. the analog input charges a sample and hold capacitor. the output of the sample and hold capacitor is the input into the converter. the converter then generates a digital result of this analog level via successive approximation. the a/d conversion of the analog input signal results in a corresponding 10-bit digital number. the a/d module has high and low volt- age reference input that is software selectable to some combination of v dd , v ss , ra2 or ra3. the a/d converter has a unique feature of being able to operate while the device is in sleep mode. to oper- ate in sleep, the a/d clock must be derived from the a/d?s internal rc oscillator. the a/d module has four registers. these registers are: ? a/d result high register (adresh) ? a/d result low register (adresl) ? a/d control register0 (adcon0) ? a/d control register1 (adcon1) the adcon0 register, shown in register 10-1, con- trols the operation of the a/d module. the adcon1 register, shown in register 10-2, configures the func- tions of the port pins. the port pins can be configured as analog inputs (ra3 can also be the voltage refer- ence), or as digital i/o. additional information on using the a/d module can be found in the picmicro? mid-range mcu family ref- erence manual (ds33023). register 10-1: adcon0 register (address: 1fh) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 adcs1 adcs0 chs2 chs1 chs0 go/done ?adon bit 7 bit 0 bit 7-6 adcs1:adcs0: a/d conversion clock select bits 00 = f osc /2 01 = f osc /8 10 = f osc /32 11 = f rc (clock derived from the internal a/d module rc oscillator) bit 5-3 chs2:chs0 : analog channel select bits 000 = channel 0 (ra0/an0) 001 = channel 1 (ra1/an1) 010 = channel 2 (ra2/an2) 011 = channel 3 (ra3/an3) 100 = channel 4 (ra5/an4) bit 2 go/done : a/d conversion status bit if adon = 1: 1 = a/d conversion in progress (setting this bit starts the a/d conversion) 0 = a/d conversion not in progress (this bit is automatically cleared by hardware when the a/d conversion is complete) bit 1 unimplemented : read as '0' bit 0 adon : a/d on bit 1 = a/d converter module is operating 0 = a/d converter module is shut-off and consumes no operating current legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown
pic16f872 ds30221c-page 80 ? 2006 microchip technology inc. register 10-2: adcon1 register (address: 9fh) u-0 u-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 bit 7 bit 0 bit 7 adfm: a/d result format select bit 1 = right justified. six most significant bits of adresh are read as ?0?. 0 = left justified. six least significant bits of adresl are read as ?0?. bit 6-4 unimplemented: read as '0' bit 3-0 pcfg3:pcfg0 : a/d port configuration control bits: note 1: this column indicates the number of analog channels available as a/d inputs and the number of analog channels used as voltage reference inputs. legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? - n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown a = analog input d = digital i/o pcfg3: pcfg0 an4 ra5 an3 ra3 an2 ra2 an1 ra1 an0 ra0 v ref +v ref - c han / refs (1) 0000 aaaaav dd v ss 8/0 0001 av ref +a a a ra3v ss 7/1 0010 aaaaav dd v ss 5/0 0011 av ref +a a a ra3v ss 4/1 0100 dadaav dd v ss 3/0 0101 dv ref +d a a ra3v ss 2/1 011x dddddv dd v ss 0/0 1000 av ref +v ref -a a ra3ra2 6/2 1001 aaaaav dd v ss 6/0 1010 av ref +a a a ra3v ss 5/1 1011 av ref +v ref -a a ra3ra2 4/2 1100 av ref +v ref -a a ra3ra2 3/2 1101 dv ref +v ref -a a ra3ra2 2/2 1110 ddddav dd v ss 1/0 1111 dv ref +v ref -d a ra3ra2 1/2
? 2006 microchip technology inc. ds30221c-page 81 pic16f872 the adresh:adresl registers contain the 10-bit result of the a/d conversion. when the a/d conversion is complete, the result is loaded into this a/d result reg- ister pair, the go/done bit (adcon0<2>) is cleared and the a/d interrupt flag bit adif is set. the block dia- gram of the a/d module is shown in figure 10-1. after the a/d module has been configured as desired, the selected channel must be acquired before the con- version is started. the analog input channels must have their corresponding tris bits selected as inputs. to determine sample time, see section 10.1. after this acquisition time has elapsed, the a/d conversion can be started. these steps should be followed for doing an a/d conversion: 1. configure the a/d module: ? configure analog pins/voltage reference and digital i/o (adcon1) ? select a/d input channel (adcon0) ? select a/d conversion clock (adcon0) ? turn on a/d module (adcon0) 2. configure a/d interrupt (if desired): ? clear adif bit ? set adie bit ? set peie bit ? set gie bit 3. wait the required acquisition time. 4. start conversion: ? set go/done bit (adcon0) 5. wait for a/d conversion to complete, by either: ? polling for the go/done bit to be cleared (with interrupts enabled); or ? waiting for the a/d interrupt 6. read a/d result register pair (adresh:adresl), clear bit adif if required. 7. for the next conversion, go to step 1 or step 2, as required. the a/d conversion time per bit is defined as t ad . figure 10-1: a/d block diagram (input voltage) v ain v ref + (reference voltage) v dd pcfg3:pcfg0 chs2:chs0 ra5/an4 ra3/an3/v ref + ra2/an2/v ref - ra1/an1 ra0/an0 100 011 010 001 000 a/d converter v ref - (reference voltage) v ss pcfg3:pcfg0
pic16f872 ds30221c-page 82 ? 2006 microchip technology inc. 10.1 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 10-2. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ), figure 10-2. the maximum recommended impedance for analog sources is 10 k . as the impedance is decreased, the acquisition time may be decreased. after the analog input channel is selected (changed), this acquisition must be done before the conversion can be started. equation 10-1 may be used to calculate the minimum acquisition time. this equation assumes that 1/2 lsb error is used (1024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. to calculate the minimum acquisition time, t acq , see the picmicro? mid-range reference manual (ds33023). equation 10-1: acquisition time figure 10-2: analog input model t acq t c t acq = = = = = = = amplifier settling time + hold capacitor charging time + temperature coefficient t amp + t c + t coff 2 s + t c + [(temperature -25 c)(0.05 s/ c)] c hold (r ic + r ss + r s ) in(1/2047) - 120 pf (1 k + 7 k + 10 k ) in(0.0004885) 16.47 s 2 s + 16.47 s + [(50 c -25 c)(0.05 s/ c) 19.72 s note 1: the reference voltage (v ref ) has no effect on the equation, since it cancels itself out. 2: the charge holding capacitor (c hold ) is not discharged after each conversion. 3: the maximum recommended impedance for analog sources is 10 k . this is required to meet the pin leakage specification. c pin va r s anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss r ss c hold = dac capacitance v ss 6v sampling switch 5v 4v 3v 2v 567891011 (k ) v dd = 120 pf 500 na legend c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions
? 2006 microchip technology inc. ds30221c-page 83 pic16f872 10.2 selecting the a/d conversion clock the a/d conversion time per bit is defined as t ad . the a/d conversion requires a minimum 12t ad per 10-bit conversion. the source of the a/d conversion clock is software selected. the four possible options for t ad are: ?2t osc ?8t osc ?32t osc ? internal a/d module rc oscillator (2-6 s) for correct a/d conversions, the a/d conversion clock (t ad ) must be selected to ensure a minimum t ad time of 1.6 s. table 10-1shows the resultant t ad times derived from the device operating frequencies and the a/d clock source selected. 10.3 configuring analog port pins the adcon1, and tris registers control the operation of the a/d port pins. the port pins that are desired as analog inputs must have their corresponding tris bits set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. the a/d operation is independent of the state of the chs2:chs0 bits and the tris bits. table 10-1: t ad vs. maximum device operating frequencies (standard devices (c)) note 1: when reading the port register, any pin configured as an analog input channel will read as cleared (a low level). pins config- ured as digital inputs will convert an ana- log input. analog levels on a digitally configured input will not affect the conver- sion accuracy. 2: analog levels on any pin that is defined as a digital input (including the an7:an0 pins), may cause the input buffer to con- sume current that is out of the device specifications. ad clock source (t ad ) maximum device frequency operation adcs1:adcs0 2t osc 00 1.25 mhz 8t osc 01 5 mhz 32t osc 10 20 mhz rc (1, 2, 3) 11 (note 1) note 1: the rc source has a typical t ad time of 4 s, but can vary between 2-6 s. 2: when the device frequencies are greater than 1 mhz, the rc a/d conversion clock source is only recom- mended for sleep operation. 3: for extended voltage devices (lc), please refer to the electrical characteristics (sections 14.1 and 14.2).
pic16f872 ds30221c-page 84 ? 2006 microchip technology inc. 10.4 a/d conversions clearing the go/done bit during a conversion will abort the current conversion. the a/d result register pair will not be updated with the partially completed a/d conversion sample. that is, the adresh:adresl registers will continue to contain the value of the last completed conversion (or the last value written to the adresh:adresl registers). after the a/d conversion is aborted, acquisition on the selected channel is automatically started. the go/done bit can then be set to start the conversion. in figure 10-3, after the go bit is set, the first time seg- ment has a minimum of t cy and a maximum of t ad . figure 10-3: a/d conversion t ad cycles 10.4.1 a/d result registers the adresh:adresl register pair is the location where the 10-bit a/d result is loaded at the completion of the a/d conversion. this register pair is 16-bits wide. the a/d module gives the flexibility to left or right justify the 10-bit result in the 16-bit result register. the a/d format select bit (adfm) controls this justification. figure 10-4 shows the operation of the a/d result justi- fication. the extra bits are loaded with ?0?s?. when an a/d result will not overwrite these locations (a/d disable), these registers may be used as two general purpose 8-bit registers. figure 10-4: a/d result justification note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 9 set go bit holding capacitor is disconnected fr om analog input (typically 100 ns) b9 b8 b7 b6 b5 b4 b3 b2 t ad 10 t ad 11 b1 b0 t cy to t ad conversion starts adres is loaded go bit is cleared adif bit is set holding capacitor is connected to analog input 10-bit result adresh adresl 0000 00 adfm = 0 0 2 1 0 7 7 10-bit result adresh adresl 10-bit result 0000 00 7 0 7 6 5 0 adfm = 1 right justified left justified
? 2006 microchip technology inc. ds30221c-page 85 pic16f872 10.5 a/d operation during sleep the a/d module can operate during sleep mode. this requires that the a/d clock source be set to rc (adcs1:adcs0 = 11 ). when the rc clock source is selected, the a/d module waits one instruction cycle before starting the conversion. this allows the sleep instruction to be executed, which eliminates all digital switching noise from the conversion. when the conver- sion is completed, the go/done bit will be cleared and the result loaded into the adres register. if the a/d interrupt is enabled, the device will wake-up from sleep. if the a/d interrupt is not enabled, the a/d mod- ule will then be turned off, although the adon bit will remain set. when the a/d clock source is another clock option (not rc), a sleep instruction will cause the present conver- sion to be aborted and the a/d module to be turned off, though the adon bit will remain set. turning off the a/d places the a/d module in its lowest current consumption state. 10.6 effects of a reset a device reset forces all registers to their reset state. this forces the a/d module to be turned off, and any conversion is aborted. all a/d input pins are con- figured as analog inputs. the value that is in the adresh:adresl registers is not modified for a power-on reset. the adresh:adresl registers will contain unknown data after a power-on reset. table 10-2: registers/bits associated with a/d note: for the a/d module to operate in sleep, the a/d clock source must be set to rc (adcs1:adcs0 = 11 ). to allow the con- version to occur during sleep, ensure the sleep instruction immediately follows the instruction that sets the go/done bit. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 por, bor mclr , wdt 0bh,8bh, 10bh, 18bh intcon gie peie tmr0ie inte rbie tmr0if intf rbif 0000 000x 0000 000u 0ch pir1 (1) adif (1) (1) sspif ccp1if tmr2if tmr1if r0rr 0000 0000 0000 8ch pie1 (1) adie (1) (1) sspie ccp1ie tmr2ie tmr1ie r0rr 0000 0000 0000 1eh adresh a/d result register high byte xxxx xxxx uuuu uuuu 9eh adresl a/d result register low byte xxxx xxxx uuuu uuuu 1fh adcon0 adcs1 adcs0 chs2 chs1 chs0 go/done ?adon 0000 00-0 0000 00-0 9fh adcon1 adfm ? ? ? pcfg3 pcfg2 pcfg1 pcfg0 --0- 0000 --0- 0000 85h trisa ? ? porta data direction register --11 1111 --11 1111 05h porta ? ? porta data latch when written: porta pins when read --0x 0000 --0u 0000 legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. shaded cells are not used for a/d conversion. note 1: these bits are reserved; always maintain clear.
pic16f872 ds30221c-page 86 ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. ds30221c-page 87 pic16f872 11.0 special features of the cpu the pic16f872 microcontroller has a host of features intended to maximize system reliability, minimize cost through elimination of external components, provide power saving operating modes and offer code protec- tion. these are: ? oscillator selection ? reset - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor) ? interrupts ? watchdog timer (wdt) ? sleep ? code protection ? id locations ? in-circuit serial programming ? low voltage in-circuit serial programming ? in-circuit debugger the microcontrollers have a watchdog timer, which can be shut-off only through configuration bits. it runs off its own rc oscillator for added reliability. there are two timers that offer necessary delays on power-up. one is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. the other is the power-up timer (pwrt), which provides a fixed delay of 72 ms (nomi- nal) on power-up only. it is designed to keep the part in reset while the power supply stabilizes. with these two timers on-chip, most applications need no external reset circuitry. sleep mode is designed to offer a very low current power-down mode. the user can wake-up from sleep through external reset, watchdog timer wake-up, or through an interrupt. several oscillator options are also made available to allow the part to fit the application. the rc oscillator option saves system cost, while the lp crystal option saves power. a set of configuration bits is used to select various options. additional information on special features is available in the picmicro? mid-range reference manual, (ds33023). 11.1 configuration bits the configuration bits can be programmed (read as '0'), or left unprogrammed (read as '1'), to select various device configurations. the erased, or unprogrammed, value of the configuration word is 3fffh. these bits are mapped in program memory location 2007h. it is important to note that address 2007h is beyond the user program memory space, which can be accessed only during programming.
pic16f872 ds30221c-page 88 ? 2006 microchip technology inc. register 11-1: configuration word (address: 2007h) (1) r/p-1 r/p-1 r/p-1 u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 cp1 cp0 debug ? wrt cpd lvp boden cp1 cp0 pwrte wdte f0sc1 f0sc0 bit13 bit0 bit 13-12 bit 5-4 cp1:cp0: flash program memory code protection bits (2) 11 = code protection off 10 = not supported 01 = not supported 00 = all memory code protected bit 11 debug: in-circuit debugger mode bit 1 = in-circuit debugger disabled, rb6 and rb7 are general purpose i/o pins 0 = in-circuit debugger enabled, rb6 and rb7 are dedicated to the debugger bit 10 unimplemented: read as ?1? bit 9 wrt: flash program memory write enable bit 1 = unprotected program memory may be written to by eecon control 0 = unprotected program memory may not be written to by eecon control bit 8 cpd: data eeprom memory code protection bit 1 = code protection off 0 = data eeprom memory code protected bit 7 lvp : low voltage in-circuit serial programming enable bit 1 = rb3/pgm pin has pgm function, low voltage programming enabled 0 = rb3 is digital i/o, hv on mclr must be used for programming bit 6 boden : brown-out reset enable bit (3) 1 = bor enabled 0 = bor disabled bit 3 pwrte : power-up timer enable bit (3) 1 = pwrt disabled 0 = pwrt enabled bit 2 wdte : watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled bit 1-0 fosc1:fosc0 : oscillator selection bits 11 = rc oscillator 10 = hs oscillator 01 = xt oscillator 00 = lp oscillator note 1: the erased (unprogrammed) value of the configuration word is 3fffh. 2: all of the cp1:cp0 pairs have to be given the same value to enable the code protection scheme listed. 3: enabling brown-out reset automatically enables power-up timer (pwrt), regardless of the value of bit pwrte . ensure the power-up timer is enabled any time brown-out reset is enabled. legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? - n = value when device is unprogrammed u = unchanged from programmed state
? 2006 microchip technology inc. ds30221c-page 89 pic16f872 11.2 oscillator configurations 11.2.1 oscillator types the pic16f872 can be operated in four different oscil- lator modes. the user can program two configuration bits (fosc1 and fosc0) to select one of these four modes: ? lp low power crystal ? xt crystal/resonator ? hs high speed crystal/resonator ? rc resistor/capacitor 11.2.2 crystal oscillator/ceramic resonators in xt, lp or hs modes, a crystal or ceramic resonator is connected to the osc1/clkin and osc2/clkout pins to establish oscillation (figure 11-1). the pic16f872 oscillator design requires the use of a par- allel cut crystal. use of a series cut crystal may give a frequency out of the crystal manufacturers specifica- tions. when in xt, lp or hs modes, the device can have an external clock source to drive the osc1/ clkin pin (figure 11-2). figure 11-1: crystal/ceramic resonator operation (hs, xt or lp osc configuration) figure 11-2: external clock input operation (hs, xt or lp osc configuration) table 11-1: ceramic resonators note 1: see table 11-1 and table 11-2 for recom- mended values of c1 and c2. 2: a series resistor (rs) may be required for at strip cut crystals. 3: rf varies with the crystal chosen. c1 (1) c2 (1) xtal osc2 osc1 rf (3) sleep to logic pic16f87x rs (2) internal ranges tested: mode freq osc1 osc2 xt 455 khz 2.0 mhz 4.0 mhz 68 - 100 pf 15 - 68 pf 15 - 68 pf 68 - 100 pf 15 - 68 pf 15 - 68 pf hs 8.0 mhz 16.0 mhz 10 - 68 pf 10 - 22 pf 10 - 68 pf 10 - 22 pf these values are for design guidance only. see notes following table 11-2. resonators used: 455 khz panasonic efo-a455k04b 0.3% 2.0 mhz murata erie csa2.00mg 0.5% 4.0 mhz murata erie csa4.00mg 0.5% 8.0 mhz murata erie csa8.00mt 0.5% 16.0 mhz murata erie csa16.00mx 0.5% all resonators used did not have built-in capacitors. osc1 osc2 open clock from ext. system pic16f87x
pic16f872 ds30221c-page 90 ? 2006 microchip technology inc. table 11-2: capacitor selection for crystal oscillator 11.2.3 rc oscillator for timing insensitive applications, the ?rc? device option offers additional cost savings. the rc oscillator frequency is a function of the supply voltage, the resis- tor (r ext ) and capacitor (c ext ) values, and the operat- ing temperature. in addition to this, the oscillator frequency will vary from unit to unit due to normal pro- cess parameter variation. furthermore, the difference in lead frame capacitance between package types will also affect the oscillation frequency, especially for low c ext values. the user also needs to take into account variation due to tolerance of external r and c compo- nents used. figure 11-3 shows how the r/c combina- tion is connected to the pic16f872. figure 11-3: rc oscillator mode osc type crystal freq cap. range c1 cap. range c2 lp 32 khz 33 pf 33 pf 200 khz 15 pf 15 pf xt 200 khz 47-68 pf 47-68 pf 1 mhz 15 pf 15 pf 4 mhz 15 pf 15 pf hs 4 mhz 15 pf 15 pf 8 mhz 15-33 pf 15-33 pf 20 mhz 15-33 pf 15-33 pf these values are for design guidance only. see notes following this table. crystals used 32 khz epson c-001r32.768k-a 20 ppm 200 khz std xtl 200.000khz 20 ppm 1 mhz ecs ecs-10-13-1 50 ppm 4 mhz ecs ecs-40-20-1 50 ppm 8 mhz epson ca-301 8.000m-c 30 ppm 20 mhz epson ca-301 20.000m-c 30 ppm note 1: higher capacitance increases the stability of oscillator, but also increases the start- up time. 2: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external compo- nents. 3: rs may be required in hs mode, as well as xt mode, to avoid overdriving crystals with low drive level specification. 4: when migrating from other picmicro ? devices, oscillator performance should be verified. osc2/clkout c ext r ext pic16f87x osc1 f osc /4 internal clock v dd v ss recommended values: 3 k r ext 100 k c ext > 20pf
? 2006 microchip technology inc. ds30221c-page 91 pic16f872 11.3 reset the pic16f872 differentiates between various kinds of reset: ? power-on reset (por) ?mclr reset during normal operation ?mclr reset during sleep ? wdt reset (during normal operation) ? wdt wake-up (during sleep) ? brown-out reset (bor) some registers are not affected in any reset condi- tion. their status is unknown on por and unchanged in any other reset. most other registers are reset to a ?reset state? on power-on reset (por), on the mclr and wdt reset, on mclr reset during sleep, and brown-out reset (bor). they are not affected by a wdt wake-up, which is viewed as the resumption of normal operation. the to and pd bits are set or cleared differently in different reset situa- tions, as indicated in table 11-4. these bits are used in software to determine the nature of the reset. see table 11-6 for a full description of reset states of all registers. a simplified block diagram of the on-chip reset circuit is shown in figure 11-4. these devices have a mclr noise filter in the mclr reset path. the filter will detect and ignore small pulses. it should be noted that a wdt reset does not drive mclr pin low. figure 11-4: simplified block diagram of on-chip reset circuit s r q external reset mclr v dd osc1 wdt module v dd rise detect ost/pwrt on-chip rc osc wdt time-out power-on reset ost 10-bit ripple counter pwrt chip_reset 10-bit ripple counter reset enable ost enable pwrt sleep note 1: this is a separate oscillator from the rc oscillator of the clkin pin. brown-out reset boden (1)
pic16f872 ds30221c-page 92 ? 2006 microchip technology inc. 11.4 power-on reset (por) a power-on reset pulse is generated on-chip when v dd rise is detected (in the range of 1.2v - 1.7v). to take advantage of the por, tie the mclr pin directly (or through a resistor) to v dd . this will eliminate exter- nal rc components usually needed to create a power- on reset. a maximum rise time for v dd is specified. see electrical specifications for details. when the device starts normal operation (exits the reset condition), device operating parameters (volt- age, frequency, temperature,...) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. brown-out reset may be used to meet the start-up conditions. for additional information, refer to application note (an007), ?power-up trouble shooting? , (ds00007). 11.5 power-up timer (pwrt) the power-up timer provides a fixed 72 ms nominal time-out on power-up only from the por. the power- up timer operates on an internal rc oscillator. the chip is kept in reset as long as the pwrt is active. the pwrt?s time delay allows v dd to rise to an accept- able level. a configuration bit is provided to enable/dis- able the pwrt. the power-up time delay will vary from chip to chip due to v dd , temperature and process variation. see dc parameters for details (t pwrt , parameter #33). 11.6 oscillator start-up timer (ost) the oscillator start-up timer (ost) provides a delay of 1024 oscillator cycles (from osc1 input) after the pwrt delay is over (if pwrt is enabled). this helps to ensure that the crystal oscillator or resonator has started and stabilized. the ost time-out is invoked only for xt, lp and hs modes and only on power-on reset or wake-up from sleep. 11.7 brown-out reset (bor) the configuration bit, boden, can enable or disable the brown-out reset circuit. if v dd falls below v bor (parameter #d005, about 4v) for longer than t bor (parameter #35, about 100 s), the brown-out situation will reset the device. if v dd falls below v bor for less than t bor , a reset may not occur. once the brown-out occurs, the device will remain in brown-out reset until v dd rises above v bor . the power-up timer then keeps the device in reset for t pwrt (parameter #33, about 72 ms). if v dd should fall below v bor during t pwrt , the brown-out reset pro- cess will restart when v dd rises above v bor with the power-up timer reset. the power-up timer is always enabled when the brown-out reset circuit is enabled, regardless of the state of the pwrt configuration bit. 11.8 time-out sequence on power-up, the time-out sequence is as follows: the pwrt delay starts (if enabled) when a por reset occurs. then, ost starts counting 1024 oscillator cycles when pwrt ends (lp, xt, hs). when the ost ends, the device comes out of reset. if mclr is kept low long enough, the time-outs will expire. bringing mclr high will begin execution imme- diately. this is useful for testing purposes or to synchro- nize more than one pic16f872 device operating in parallel. table 11-5 shows the reset conditions for the status, pcon and pc registers, while table 11-6 shows the reset conditions for all the registers. 11.9 power control/status register (pcon) the power control/status register, pcon, has two bits. bit 0 is the brown-out reset status bit (bor) . bit bor is unknown on a power-on reset. it must then be set by the user and checked on subsequent resets to see if bit bor cleared, indicating a bor occurred. when the brown-out reset is disabled, the state of the bor bit is unpredictable and is, therefore, not valid at any time. bit 1 is the power-on reset status bit (por ). it is cleared on a power-on reset and unaffected other- wise. the user must set this bit following a power-on reset. table 11-3: time-out in various situations oscillator configuration power-up brown-out wake-up from sleep pwrte = 0 pwrte = 1 xt, hs, lp 72 ms + 1024t osc 1024t osc 72 ms + 1024t osc 1024t osc rc 72 ms ? 72 ms ?
? 2006 microchip technology inc. ds30221c-page 93 pic16f872 table 11-4: status bits and their significance table 11-5: reset condition for special registers por bor to pd 0x11 power-on reset 0x0x illegal, to is set on por 0xx0 illegal, pd is set on por 1011 brown-out reset 1101 wdt reset 1100 wdt wake-up 11uu mclr reset during normal operation 1110 mclr reset during sleep or interrupt wake-up from sleep condition program counter status register pcon register power-on reset 000h 0001 1xxx ---- --0x mclr reset during normal operation 000h 000u uuuu ---- --uu mclr reset during sleep 000h 0001 0uuu ---- --uu wdt reset 000h 0000 1uuu ---- --uu wdt wake-up pc + 1 uuu0 0uuu ---- --uu brown-out reset 000h 0001 1uuu ---- --u0 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu ---- --uu legend: u = unchanged, x = unknown, - = unimplemented bit, read as '0' note 1: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). table 11-6: initialization conditions for all registers register power-on reset, brown-out reset mclr resets wdt reset wake-up via wdt or interrupt w xxxx xxxx uuuu uuuu uuuu uuuu indf n/a n/a n/a tmr0 xxxx xxxx uuuu uuuu uuuu uuuu pcl 0000h 0000h pc + 1 (2) status 0001 1xxx 000q quuu (3) uuuq quuu (3) fsr xxxx xxxx uuuu uuuu uuuu uuuu porta --0x 0000 --0u 0000 --uu uuuu portb xxxx xxxx uuuu uuuu uuuu uuuu portc xxxx xxxx uuuu uuuu uuuu uuuu pclath ---0 0000 ---0 0000 ---u uuuu intcon 0000 000x 0000 000u uuuu uuuu (1) pir1 r0rr 0000 r0rr 0000 rurr uuuu (1) pir2 -r-0 0--r -r-0 0--r -r-u u--r (1) legend: u = unchanged, x = unknown, - = unimplemented bit, read as '0', q = value depends on condition, r = reserved, maintain clear note 1: one or more bits in intcon, pir1 and/or pir2 will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 3: see table 11-5 for reset value for specific condition.
pic16f872 ds30221c-page 94 ? 2006 microchip technology inc. tmr1l xxxx xxxx uuuu uuuu uuuu uuuu tmr1h xxxx xxxx uuuu uuuu uuuu uuuu t1con --00 0000 --uu uuuu --uu uuuu tmr2 0000 0000 0000 0000 uuuu uuuu t2con -000 0000 -000 0000 -uuu uuuu sspbuf xxxx xxxx uuuu uuuu uuuu uuuu sspcon 0000 0000 0000 0000 uuuu uuuu ccpr1l xxxx xxxx uuuu uuuu uuuu uuuu ccpr1h xxxx xxxx uuuu uuuu uuuu uuuu ccp1con --00 0000 --00 0000 --uu uuuu adresh xxxx xxxx uuuu uuuu uuuu uuuu adcon0 0000 00-0 0000 00-0 uuuu uu-u option_reg 1111 1111 1111 1111 uuuu uuuu trisa --11 1111 --11 1111 --uu uuuu trisb 1111 1111 1111 1111 uuuu uuuu trisc 1111 1111 1111 1111 uuuu uuuu pie1 r0rr 0000 r0rr 0000 rurr uuuu pie2 -r-0 0--r -r-0 0--r -r-u u--r pcon ---- --qq ---- --uu ---- --uu sspcon2 0000 0000 0000 0000 uuuu uuuu pr2 1111 1111 1111 1111 1111 1111 sspadd 0000 0000 0000 0000 uuuu uuuu sspstat --00 0000 --00 0000 --uu uuuu adresl xxxx xxxx uuuu uuuu uuuu uuuu adcon1 0--- 0000 0--- 0000 u--- uuuu eedata 0--- 0000 0--- 0000 u--- uuuu eeadr xxxx xxxx uuuu uuuu uuuu uuuu eedath xxxx xxxx uuuu uuuu uuuu uuuu eeadrh xxxx xxxx uuuu uuuu uuuu uuuu eecon1 x--- x000 u--- u000 u--- uuuu eecon2 ---- ---- ---- ---- ---- ---- table 11-6: initialization condition s for all registers (continued) register power-on reset, brown-out reset mclr resets wdt reset wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as '0', q = value depends on condition, r = reserved, maintain clear note 1: one or more bits in intcon, pir1 and/or pir2 will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 3: see table 11-5 for reset value for specific condition.
? 2006 microchip technology inc. ds30221c-page 95 pic16f872 figure 11-5: time-out sequence on power-up (mclr tied to v dd via rc network) figure 11-6: time-out sequence on power-up (mclr not tied to v dd ): case 1 t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset
pic16f872 ds30221c-page 96 ? 2006 microchip technology inc. figure 11-7: time-out sequence on power-up (mclr not tied to v dd ): case 2 figure 11-8: slow risetime (mclr tied to v dd via rc network) v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset 0v 1v 5v t pwrt t ost
? 2006 microchip technology inc. ds30221c-page 97 pic16f872 11.10 interrupts the pic16f872 has 10 sources of interrupt. the inter- rupt control register (intcon) records individual inter- rupt requests in flag bits. it also has individual and global interrupt enable bits. a global interrupt enable bit, gie (intcon<7>), enables (if set) all unmasked interrupts or disables (if cleared) all interrupts. when bit gie is enabled, and an interrupt?s flag bit and mask bit are set, the interrupt will vector immediately. individual interrupts can be dis- abled through their corresponding enable bits in vari- ous registers. individual interrupt bits are set, regardless of the status of the gie bit. the gie bit is cleared on reset. the ?return from interrupt? instruction, retfie , exits the interrupt routine, as well as sets the gie bit, which re-enables interrupts. the rb0/int pin interrupt, the rb port change interrupt and the tmr0 overflow interrupt flags are contained in the intcon register. the peripheral interrupt flags are contained in the spe- cial function registers, pir1 and pir2. the correspond- ing interrupt enable bits are contained in special function registers, pie1 and pie2, and the peripheral interrupt enable bit is contained in special function register, intcon. when an interrupt is responded to, the gie bit is cleared to disable any further interrupt, the return address is pushed onto the stack and the pc is loaded with 0004h. once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid recursive interrupts. for external interrupt events, such as the int pin or portb change interrupt, the interrupt latency will be three or four instruction cycles. the exact latency depends when the interrupt event occurs. the latency is the same for one or two-cycle instructions. individual interrupt flag bits are set, regardless of the status of their corresponding mask bit, peie bit, or gie bit figure 11-9: interrupt logic note: individual interrupt flag bits are set, regard- less of the status of their corresponding mask bit or the gie bit. adif adie sspif sspie ccp1if ccp1ie tmr2if tmr2ie tmr1if tmr1ie tmr0if tmr0ie intf inte rbif rbie gie peie wake-up (if in sleep mode) interrupt to cpu bclie bclif eeif eeie
pic16f872 ds30221c-page 98 ? 2006 microchip technology inc. 11.10.1 int interrupt external interrupt on the rb0/int pin is edge triggered, either rising if bit intedg (option_reg<6>) is set, or falling if the intedg bit is clear. when a valid edge appears on the rb0/int pin, flag bit intf (intcon<1>) is set. this interrupt can be disabled by clearing enable bit inte (intcon<4>). flag bit intf must be cleared in software in the interrupt service routine before re-enabling this interrupt. the int inter- rupt can wake-up the processor from sleep, if bit inte was set prior to going into sleep. the status of global interrupt enable bit gie, decides whether or not the processor branches to the interrupt vector following wake-up. see section 11.13 for details on sleep mode. 11.10.2 tmr0 interrupt an overflow (ffh 00h) in the tmr0 register will set flag bit tmr0if (intcon<2>). the interrupt can be enabled/disabled by setting/clearing enable bit tmr0ie (intcon<5>), see section 5.0. 11.10.3 portb intcon change an input change on portb<7:4> sets flag bit rbif (intcon<0>). the interrupt can be enabled/disabled by setting/clearing enable bit rbie (intcon<4>), see section 4.2. 11.11 context saving during interrupts during an interrupt, only the return pc value is saved on the stack. typically, users may wish to save key reg- isters during an interrupt, (i.e., w register and status register). this will have to be implemented in software. since the upper 16 bytes of each bank are common in pic16f872 devices, temporary holding registers, w_temp, status_temp and pclath_temp, should be placed in here. these 16 locations don?t require banking and therefore, make it easier for con- text save and restore. the same code shown in example 11-1 can be used. example 11-1: saving status, w, and pclath registers in ram movwf w_temp ;copy w to temp register swapf status,w ;swap status to be saved into w clrf status ;bank 0, regardless of current bank, clears irp,rp1,rp0 movwf status_temp ;save status to bank zero status_temp register movf pclath, w ;only required if using pages 1, 2 and/or 3 movwf pclath_temp ;save pclath into w clrf pclath ;page zero, regardless of current page : :(isr) ;(insert user code here) : movf pclath_temp, w ;restore pclath movwf pclath ;move w into pclath swapf status_temp,w ;swap status_temp register into w ;(sets bank to original state) movwf status ;move w into status register swapf w_temp,f ;swap w_temp swapf w_temp,w ;swap w_temp into w
? 2006 microchip technology inc. ds30221c-page 99 pic16f872 11.12 watchdog timer (wdt) the watchdog timer is a free running on-chip rc oscil- lator, which does not require any external components. this rc oscillator is separate from the rc oscillator of the osc1/clki pin. that means that the wdt will run, even if the clock on the osc1/clki and osc2/clko pins of the device has been stopped, for example, by execution of a sleep instruction. during normal operation, a wdt time-out generates a device reset (watchdog timer reset). if the device is in sleep mode, a wdt time-out causes the device to wake-up and continue with normal operation (watch- dog timer wake-up). the to bit in the status regis- ter will be cleared upon a watchdog timer time-out. the wdt can be permanently disabled by clearing configuration bit wdte (section 11.1). wdt time-out period values may be found in the elec- trical specifications section under parameter #31. val- ues for the wdt prescaler (actually a postscaler, but shared with the timer0 prescaler) may be assigned using the option_reg register. figure 11-10: watchdog timer block diagram table 11-7: summary of watchdog timer registers note 1: the clrwdt and sleep instructions clear the wdt and the postscaler, if assigned to the wdt, and prevent it from timing out and generating a device reset condition. 2: when a clrwdt instruction is executed and the prescaler is assigned to the wdt, the prescaler count will be cleared, but the prescaler assignment is not changed. from tmr0 clock source (figure 5-1) to tmr0 (figure 5-1) postscaler wdt timer wdt enable bit 0 1 m u x psa 8 - to - 1 mux ps2:ps0 0 1 mux psa wdt time-out 8 note: psa and ps2:ps0 are bits in the option_reg register. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 2007h config. bits (1) boden (1) cp1 cp0 pwrte (1) wdte fosc1 fosc0 81h,181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 legend: shaded cells are not used by the watchdog timer. note 1: see register 11-1 for operation of these bits.
pic16f872 ds30221c-page 100 ? 2006 microchip technology inc. 11.13 power-down mode (sleep) power-down mode is entered by executing a sleep instruction. if enabled, the watchdog timer will be cleared but keeps running, the pd bit (status<3>) is cleared, the to (status<4>) bit is set, and the oscillator driver is turned off. the i/o ports maintain the status they had before the sleep instruction was executed (driving high, low, or hi-impedance). for lowest current consumption in this mode, place all i/o pins at either v dd or v ss , ensure no external cir- cuitry is drawing current from the i/o pin, power-down the a/d and disable external clocks. pull all i/o pins that are hi-impedance inputs, high or low externally, to avoid switching currents caused by floating inputs. the t0cki input should also be at v dd or v ss for lowest current consumption. the contribution from on-chip pull-ups on portb should also be considered. the mclr pin must be at a logic high level (v ihmc ). 11.13.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin. 2. watchdog timer wake-up (if wdt was enabled). 3. interrupt from int pin, rb port change or peripheral interrupt. external mclr reset will cause a device reset. all other events are considered a continuation of program execution and cause a ?wake-up?. the to and pd bits in the status register can be used to determine the cause of device reset. the pd bit, which is set on power-up, is cleared when sleep is invoked. the to bit is cleared if a wdt time-out occurred and caused wake-up. the following peripheral interrupts can wake the device from sleep: 1. psp read or write. 2. tmr1 interrupt. timer1 must be operating as an asynchronous counter. 3. ccp capture mode interrupt. 4. special event trigger (timer1 in asynchronous mode using an external clock). 5. ssp (start/stop) bit detect interrupt. 6. ssp transmit or receive in slave mode (spi/i 2 c). 7. usart rx or tx (synchronous slave mode). 8. a/d conversion (when a/d clock source is rc). 9. eeprom write operation completion. other peripherals cannot generate interrupts, since during sleep, no on-chip clocks are present. when the sleep instruction is being executed, the next instruction (pc + 1) is pre-fetched. for the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). wake-up is regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction and then branches to the inter- rupt address (0004h). in cases where the execution of the instruction following sleep is not desirable, the user should have a nop after the sleep instruction. 11.13.2 wake-up using interrupts when global interrupts are disabled (gie cleared) and any interrupt source has both its interrupt enable bit and interrupt flag bit set, one of the following will occur: ? if the interrupt occurs before the execution of a sleep instruction, the sleep instruction will com- plete as a nop . therefore, the wdt and wdt postscaler will not be cleared, the to bit will not be set and pd bits will not be cleared. ? if the interrupt occurs during or after the execu- tion of a sleep instruction, the device will imme- diately wake-up from sleep. the sleep instruction will be completely executed before the wake-up. therefore, the wdt and wdt postscaler will be cleared, the to bit will be set and the pd bit will be cleared. even if the flag bits were checked before executing a sleep instruction, it may be possible for flag bits to become set before the sleep instruction completes. to determine whether a sleep instruction executed, test the pd bit. if the pd bit is set, the sleep instruction was executed as a nop . to ensure that the wdt is cleared, a clrwdt instruc- tion should be executed before a sleep instruction.
? 2006 microchip technology inc. ds30221c-page 101 pic16f872 figure 11-11: wake-up from sleep through interrupt 11.14 in-circuit debugger when the debug bit in the configuration word is programmed to a '0', the in-circuit debugger function- ality is enabled. this function allows simple debugging functions when used with mplab ? ide. when the microcontroller has this feature enabled, some of the resources are not available for general use. table 11-8 shows which features are consumed by the back- ground debugger. table 11-8: debugger resources to use the in-circuit debugger function of the micro- controller, the design must implement in-circuit serial programming connections to mclr /v pp , v dd , gnd, rb7 and rb6. this will interface to the in-circuit debugger module available from microchip or one of the third party development tool companies. 11.15 program verification/code protection if the code protection bit(s) have not been pro- grammed, the on-chip program memory can be read out for verification purposes. 11.16 id locations four memory locations (2000h - 2003h) are designated as id locations, where the user can store checksum or other code identification numbers. these locations are not accessible during normal execution, but are read- able and writable during program/verify. it is recom- mended that only the 4 least significant bits of the id location are used. q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 clkout (4) int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed pc pc+1 pc+2 inst(pc) = sleep inst(pc - 1) inst(pc + 1) sleep processor in sleep interrupt latency (note 2) inst(pc + 2) inst(pc + 1) inst(0004h) inst(0005h) inst(0004h) dummy cycle pc + 2 0004h 0005h dummy cycle t ost (2) pc+2 note 1: xt, hs or lp oscillator mode assumed. 2: t ost = 1024t osc (drawing not to scale). this delay will not be there for rc osc mode. 3: gie = '1' assumed. in this case, after wake- up, the processor jumps to the interrupt routine. if gie = '0', execution will continue in-line. 4: clkout is not available in these osc modes, but shown here for timing reference. i/o pins rb6, rb7 stack 1 level program memory address 0000h must be nop last 100h words data memory 0x070 (0x0f0, 0x170, 0x1f0) 0x1eb - 0x1ef
pic16f872 ds30221c-page 102 ? 2006 microchip technology inc. 11.17 in-circuit serial programming pic16f872 microcontrollers can be serially pro- grammed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for power, ground, and the programming voltage. this allows customers to manufacture boards with unprogrammed devices, and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firm- ware to be programmed. when using icsp, the part must be supplied 4.5v to 5.5v if a bulk erase will be executed. this includes reprogramming of the code protect, both from an on- state to off-state. for all other cases of icsp, the part may be programmed at the normal operating voltages. this means calibration values, unique user ids or user code can be reprogrammed or added. for complete details of serial programming, please refer to the eeprom memory programming specifica- tion for the pic16f87x (ds39025). 11.18 low voltage icsp programming the lvp bit of the configuration word enables low volt- age icsp programming. this mode allows the micro- controller to be programmed via icsp, using a v dd source in the operating voltage range. this only means that v pp does not have to be brought to v ihh , but can instead be left at the normal operating voltage. in this mode, the rb3/pgm pin is dedicated to the program- ming function and ceases to be a general purpose i/o pin. during programming, v dd is applied to the mclr pin. to enter programming mode, v dd must be applied to the rb3/pgm pin, provided the lvp bit is set. the lvp bit defaults to on (?1?) from the factory. if low voltage programming mode is not used, the lvp bit can be programmed to a '0' and rb3/pgm becomes a digital i/o pin. however, the lvp bit may only be pro- grammed when programming is entered with v ihh on mclr . the lvp bit can only be charged when using high voltage on mclr . it should be noted that once the lvp bit is programmed to 0, only the high voltage programming mode is avail- able and only high voltage programming mode can be used to program the device. when using low voltage icsp, the part must be sup- plied 4.5v to 5.5v if a bulk erase will be executed. this includes reprogramming of the code protect bits from an on-state to off-state. for all other cases of low volt- age icsp, the part may be programmed at the normal operating voltage. this means calibration values, unique user ids, or user code can be reprogrammed or added. note 1: the high voltage programming mode is always available, regardless of the state of the lvp bit, by applying v ihh to the mclr pin. 2: while in low voltage icsp mode, the rb3 pin can no longer be used as a general purpose i/o pin. 3: when using low voltage icsp program- ming (lvp) and the pull-ups on portb are enabled, bit 3 in the trisb register must be cleared to disable the pull-up on rb3 and ensure the proper operation of the device.
? 2006 microchip technology inc. ds30221c-page 103 pic16f872 12.0 instruction set summary the pic16 instruction set is highly orthogonal and is comprised of three basic categories: ? byte-oriented operations ? bit-oriented operations ? literal and control operations each pic16 instruction is a 14-bit word divided into an opcode which specifies the instruction type, and one or more operands which further specify the operation of the instruction. the formats for each of the categories is presented in figure 12-1, while the various opcode fields are summarized in table 12-1. table 13-2 lists the instructions recognized by the mpasm tm assembler. a complete description of each instruction is also available in the picmicro? mid- range reference manual (ds33023). for byte-oriented instructions, ? f ? represents a file reg- ister designator and ? d ? represents a destination desig- nator. the file register designator specifies which file register is to be used by the instruction. the destination designator specifies where the result of the operation is to be placed. if ? d ? is zero, the result is placed in the w register. if ? d ? is one, the result is placed in the file register specified in the instruction. for bit-oriented instructions, ? b ? represents a bit field designator, which selects the bit affected by the opera- tion, while ? f ? represents the address of the file in which the bit is located. for literal and control operations, ? k ? represents an eight- or eleven-bit constant or literal value one instruction cycle consists of four oscillator periods; for an oscillator frequency of 4 mhz, this gives a normal instruction execution time of 1 s. all instructions are executed within a single instruction cycle, unless a con- ditional test is true or the program counter is changed as a result of an instruction. when this occurs, the exe- cution takes two instruction cycles with the second cycle executed as a nop . all instruction examples use the format ?0xhh? to repre- sent a hexadecimal number, where ?h? signifies a hexa- decimal digit. 12.1 read-modify-write operations any instruction that specifies a file register as part of the instruction performs a read-modify-write (r-m-w) operation. the register is read, the data is modified, and the result is stored according to either the instruc- tion or the destination designator ?d?. a read operation is performed on a register even if the instruction writes to that register. for example, a ? clrf portb ? instruction will read portb, clear all the data bits, then write the result back to portb. this example would have the unin- tended result that the condition that sets the rbif flag would be cleared. table 12-1: opcode field descriptions figure 12-1: general format for instructions note: to maintain upward compatibility with future pic16f872 products, do not use the option and tris instructions. field description f register file address (0x00 to 0x7f) w working register (accumulator) b bit address within an 8-bit file register k literal field, constant data or label x don't care location (= 0 or 1 ). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. d destination select; d = 0 : store result in w, d = 1: store result in file register f. default is d = 1. pc program counter to time-out bit pd power-down bit byte-oriented file register operations 13 8 7 6 0 d = 0 for destination w opcode d f (file #) d = 1 for destination f f = 7-bit file register address bit-oriented file register operations 13 10 9 7 6 0 opcode b (bit #) f (file #) b = 3-bit bit address f = 7-bit file register address literal and control operations 13 8 7 0 opcode k (literal) k = 8-bit immediate value 13 11 10 0 opcode k (literal) k = 11-bit immediate value general call and goto instructions only
pic16f872 ds30221c-page 104 ? 2006 microchip technology inc. table 12-2: pic16f872 instruction set mnemonic, operands description cycles 14-bit opcode status affected notes msb lsb byte-oriented file register operations addwf andwf clrf clrw comf decf decfsz incf incfsz iorwf movf movwf nop rlf rrf subwf swapf xorwf f, d f, d f - f, d f, d f, d f, d f, d f, d f, d f - f, d f, d f, d f, d f, d add w and f and w with f clear f clear w complement f decrement f decrement f, skip if 0 increment f increment f, skip if 0 inclusive or w with f move f move w to f no operation rotate left f through carry rotate right f through carry subtract w from f swap nibbles in f exclusive or w with f 1 1 1 1 1 1 1(2) 1 1(2) 1 1 1 1 1 1 1 1 1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0111 0101 0001 0001 1001 0011 1011 1010 1111 0100 1000 0000 0000 1101 1100 0010 1110 0110 dfff dfff lfff 0xxx dfff dfff dfff dfff dfff dfff dfff lfff 0xx0 dfff dfff dfff dfff dfff ffff ffff ffff xxxx ffff ffff ffff ffff ffff ffff ffff ffff 0000 ffff ffff ffff ffff ffff c,dc,z z z z z z z z z c c c,dc,z z 1,2 1,2 2 1,2 1,2 1,2,3 1,2 1,2,3 1,2 1,2 1,2 1,2 1,2 1,2 1,2 bit-oriented file register operations bcf bsf btfsc btfss f, b f, b f, b f, b bit clear f bit set f bit test f, skip if clear bit test f, skip if set 1 1 1 (2) 1 (2) 01 01 01 01 00bb 01bb 10bb 11bb bfff bfff bfff bfff ffff ffff ffff ffff 1,2 1,2 3 3 literal and control operations addlw andlw call clrwdt goto iorlw movlw retfie retlw return sleep sublw xorlw k k k - k k k - k - - k k add literal and w and literal with w call subroutine clear watchdog timer go to address inclusive or literal with w move literal to w return from interrupt return with literal in w return from subroutine go into standby mode subtract w from literal exclusive or literal with w 1 1 2 1 2 1 1 2 2 2 1 1 1 11 11 10 00 10 11 11 00 11 00 00 11 11 111x 1001 0kkk 0000 1kkk 1000 00xx 0000 01xx 0000 0000 110x 1010 kkkk kkkk kkkk 0110 kkkk kkkk kkkk 0000 kkkk 0000 0110 kkkk kkkk kkkk kkkk kkkk 0100 kkkk kkkk kkkk 1001 kkkk 1000 0011 kkkk kkkk c,dc,z z to ,pd z to ,pd c,dc,z z note 1: when an i/o register is modified as a function of itself ( e.g., movf portb, 1 ), the value used will be that value present on the pins themselves. for example, if the data latch is '1' for a pin configured as input and is driven low by an external device, the data will be written back with a '0'. 2: if this instruction is executed on the tmr0 register (and, wher e applicable, d = 1), the prescaler will be cleared if assigned to the timer0 module. 3: if program counter (pc) is modified, or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . note: additional information on the mid-range instruction set is available in the picmicro ? mid-range mcu family reference manual (ds33023).
? 2006 microchip technology inc. ds30221c-page 105 pic16f872 12.2 instruction descriptions addlw add literal and w syntax: [ label ] addlw k operands: 0 k 255 operation: (w) + k (w) status affected: c, dc, z description: the contents of the w register are added to the eight-bit literal 'k' and the result is placed in the w register. addwf add w and f syntax: [ label ] addwf f,d operands: 0 f 127 d [0,1] operation: (w) + (f) (destination) status affected: c, dc, z description: add the contents of the w register with register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'. andlw and literal with w syntax: [ label ] andlw k operands: 0 k 255 operation: (w) .and. (k) (w) status affected: z description: the contents of w register are and?ed with the eight-bit literal 'k'. the result is placed in the w register. andwf and w with f syntax: [ label ] andwf f,d operands: 0 f 127 d [0,1] operation: (w) .and. (f) (destination) status affected: z description: and the w register with register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'. bcf bit clear f syntax: [ label ] bcf f,b operands: 0 f 127 0 b 7 operation: 0 (f) status affected: none description: bit 'b' in register 'f' is cleared. bsf bit set f syntax: [ label ] bsf f,b operands: 0 f 127 0 b 7 operation: 1 (f) status affected: none description: bit 'b' in register 'f' is set. btfss bit test f, skip if set syntax: [ label ] btfss f,b operands: 0 f 127 0 b < 7 operation: skip if (f) = 1 status affected: none description: if bit 'b' in register 'f' is '0', the next instruction is executed. if bit 'b' is '1', then the next instruc- tion is discarded and a nop is executed instead, making this a 2t cy instruction. btfsc bit test, skip if clear syntax: [ label ] btfsc f,b operands: 0 f 127 0 b 7 operation: skip if (f) = 0 status affected: none description: if bit 'b' in register 'f' is '1', the next instruction is executed. if bit 'b', in register 'f', is '0', the next instruction is discarded, and a nop is executed instead, making this a 2t cy instruction.
pic16f872 ds30221c-page 106 ? 2006 microchip technology inc. call call subroutine syntax: [ label ] call k operands: 0 k 2047 operation: (pc)+ 1 tos, k pc<10:0>, (pclath<4:3>) pc<12:11> status affected: none description: call subroutine. first, return address (pc+1) is pushed onto the stack. the eleven-bit immedi- ate address is loaded into pc bits <10:0>. the upper bits of the pc are loaded from pclath. call is a two-cycle instruction. clrf clear f syntax: [ label ] clrf f operands: 0 f 127 operation: 00h (f) 1 z status affected: z description: the contents of register 'f' are cleared and the z bit is set. clrw clear w syntax: [ label ] clrw operands: none operation: 00h (w) 1 z status affected: z description: w register is cleared. zero bit (z) is set. clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 00h wdt 0 wdt prescaler, 1 to 1 pd status affected: to , pd description: clrwdt instruction resets the watchdog timer. it also resets the prescaler of the wdt. status bits to and pd are set. comf complement f syntax: [ label ] comf f,d operands: 0 f 127 d [0,1] operation: (f ) (destination) status affected: z description: the contents of register 'f' are complemented. if 'd' is 0, the result is stored in w. if 'd' is 1, the result is stored back in register 'f'. decf decrement f syntax: [ label ] decf f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (destination) status affected: z description: decrement register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'.
? 2006 microchip technology inc. ds30221c-page 107 pic16f872 decfsz decrement f, skip if 0 syntax: [ label ] decfsz f,d operands: 0 f 127 d [0,1] operation: (f) - 1 (destination); skip if result = 0 status affected: none description: the contents of register 'f' are decremented. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'. if the result is 1, the next instruc- tion is executed. if the result is 0, then a nop is executed instead, making it a 2t cy instruction. goto unconditional branch syntax: [ label ] goto k operands: 0 k 2047 operation: k pc<10:0> pclath<4:3> pc<12:11> status affected: none description: goto is an unconditional branch. the eleven-bit immediate value is loaded into pc bits <10:0>. the upper bits of pc are loaded from pclath<4:3>. goto is a two- cycle instruction. incf increment f syntax: [ label ] incf f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (destination) status affected: z description: the contents of register 'f' are incremented. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'. incfsz increment f, skip if 0 syntax: [ label ] incfsz f,d operands: 0 f 127 d [0,1] operation: (f) + 1 (destination), skip if result = 0 status affected: none description: the contents of register 'f' are incremented. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'. if the result is 1, the next instruc- tion is executed. if the result is 0, a nop is executed instead, making it a 2t cy instruction. iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 k 255 operation: (w) .or. k (w) status affected: z description: the contents of the w register are or?ed with the eight-bit literal 'k'. the result is placed in the w register. iorwf inclusive or w with f syntax: [ label ] iorwf f,d operands: 0 f 127 d [0,1] operation: (w) .or. (f) (destination) status affected: z description: inclusive or the w register with register 'f'. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'.
pic16f872 ds30221c-page 108 ? 2006 microchip technology inc. movf move f syntax: [ label ] movf f,d operands: 0 f 127 d [0,1] operation: (f) (destination) status affected: z description: the contents of register f are moved to a destination dependant upon the status of d. if d = 0, destination is w register. if d = 1, the destination is file register f itself. d = 1 is useful to test a file register, since status flag z is affected. movlw move literal to w syntax: [ label ] movlw k operands: 0 k 255 operation: k (w) status affected: none description: the eight-bit literal 'k' is loaded into w register. the don?t cares will assemble as 0?s. movwf move w to f syntax: [ label ] movwf f operands: 0 f 127 operation: (w) (f) status affected: none description: move data from w register to register 'f'. nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none description: no operation. retfie return from interrupt syntax: [ label ] retfie operands: none operation: tos pc, 1 gie status affected: none retlw return with literal in w syntax: [ label ] retlw k operands: 0 k 255 operation: k (w); tos pc status affected: none description: the w register is loaded with the eight-bit literal 'k'. the program counter is loaded from the top of the stack (the return address). this is a two-cycle instruction.
? 2006 microchip technology inc. ds30221c-page 109 pic16f872 rlf rotate left f through carry syntax: [ label ] rlf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c description: the contents of register 'f' are rotated one bit to the left through the carry flag. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is stored back in register 'f'. return return from subroutine syntax: [ label ] return operands: none operation: tos pc status affected: none description: return from subroutine. the stack is poped and the top of the stack (tos) is loaded into the program counter. this is a two-cycle instruction. rrf rotate right f through carry syntax: [ label ] rrf f,d operands: 0 f 127 d [0,1] operation: see description below status affected: c description: the contents of register 'f' are rotated one bit to the right through the carry flag. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed back in register 'f'. register f c register f c sleep syntax: [ label ] sleep operands: none operation: 00h wdt, 0 wdt prescaler, 1 to , 0 pd status affected: to , pd description: the power-down status bit, pd is cleared. time-out status bit, to is set. watchdog timer and its prescaler are cleared. the processor is put into sleep mode with the oscillator stopped. sublw subtract w from literal syntax: [ label ] sublw k operands: 0 k 255 operation: k - (w) ( w) status affected: c, dc, z description: the w register is subtracted (2?s complement method) from the eight-bit literal 'k'. the result is placed in the w register. subwf subtract w from f syntax: [ label ] subwf f,d operands: 0 f 127 d [0,1] operation: (f) - (w) ( destination) status affected: c, dc, z description: subtract (2?s complement method) w register from register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'.
pic16f872 ds30221c-page 110 ? 2006 microchip technology inc. swapf swap nibbles in f syntax: [ label ] swapf f,d operands: 0 f 127 d [0,1] operation: (f<3:0>) (destination<7:4>), (f<7:4>) (destination<3:0>) status affected: none description: the upper and lower nibbles of register 'f' are exchanged. if 'd' is 0, the result is placed in the w register. if 'd' is 1, the result is placed in register 'f'. xorlw exclusive or literal with w syntax: [ label ] xorlw k operands: 0 k 255 operation: (w) .xor. k ( w) status affected: z description: the contents of the w register are xor?ed with the eight-bit lit- eral 'k'. the result is placed in the w register. xorwf exclusive or w with f syntax: [ label ] xorwf f,d operands: 0 f 127 d [0,1] operation: (w) .xor. (f) ( destination) status affected: z description: exclusive or the contents of the w register with register 'f'. if 'd' is 0, the result is stored in the w register. if 'd' is 1, the result is stored back in register 'f'.
? 2006 microchip technology inc. ds30221c-page 111 pic16f872 13.0 development support the picmicro ? microcontrollers are supported with a full range of hardware and software development tools: ? integrated development environment - mplab ? ide software ? assemblers/compilers/linkers - mpasm tm assembler - mplab c17 and mplab c18 c compilers -mplink tm object linker/ mplib tm object librarian ? simulators - mplab sim software simulator ?emulators - mplab ice 2000 in-circuit emulator - icepic? in-circuit emulator ? in-circuit debugger - mplab icd ? device programmers -pro mate ? ii universal device programmer - picstart ? plus entry-level development programmer ? low cost demonstration boards - picdem tm 1 demonstration board - picdem 2 demonstration board - picdem 3 demonstration board - picdem 17 demonstration board -k ee l oq ? demonstration board 13.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8-bit microcon- troller market. the mplab ide is a windows ? -based application that contains: ? an interface to debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor ? a project manager ? customizable toolbar and key mapping ? a status bar ? on-line help the mplab ide allows you to: ? edit your source files (either assembly or ?c?) ? one touch assemble (or compile) and download to picmicro emulator and simulator tools (auto- matically updates all project information) ? debug using: - source files - absolute listing file - machine code the ability to use mplab ide with multiple debugging tools allows users to easily switch from the cost- effective simulator to a full-featured emulator with minimal retraining. 13.2 mpasm assembler the mpasm assembler is a full-featured universal macro assembler for all picmicro mcu?s. the mpasm assembler has a command line interface and a windows shell. it can be used as a stand-alone application on a windows 3.x or greater system, or it can be used through mplab ide. the mpasm assem- bler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, an abso- lute lst file that contains source lines and generated machine code, and a cod file for debugging. the mpasm assembler features include: ? integration into mplab ide projects. ? user-defined macros to streamline assembly code. ? conditional assembly for multi-purpose source files. ? directives that allow complete control over the assembly process. 13.3 mplab c17 and mplab c18 c compilers the mplab c17 and mplab c18 code development systems are complete ansi ?c? compilers for microchip?s pic17cxxx and pic18cxxx family of microcontrollers, respectively. these compilers provide powerful integration capabilities and ease of use not found with other compilers. for easier source level debugging, the compilers pro- vide symbol information that is compatible with the mplab ide memory display.
pic16f872 ds30221c-page 112 ? 2006 microchip technology inc. 13.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c17 and mplab c18 c compilers. it can also link relocatable objects from pre-compiled libraries, using directives from a linker script. the mplib object librarian is a librarian for pre- compiled code to be used with the mplink object linker. when a routine from a library is called from another source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the mplib object librarian manages the creation and modification of library files. the mplink object linker features include: ? integration with mpasm assembler and mplab c17 and mplab c18 c compilers. ? allows all memory areas to be defined as sections to provide link-time flexibility. the mplib object librarian features include: ? easier linking because single libraries can be included instead of many smaller files. ? helps keep code maintainable by grouping related modules together. ? allows libraries to be created and modules to be added, listed, replaced, deleted or extracted. 13.5 mplab sim software simulator the mplab sim software simulator allows code devel- opment in a pc-hosted environment by simulating the picmicro series microcontrollers on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a file, or user-defined key press, to any of the pins. the execution can be performed in single step, execute until break, or trace mode. the mplab sim simulator fully supports symbolic debug- ging using the mplab c17 and the mplab c18 c com- pilers and the mpasm assembler. the software simulator offers the flexibility to develop and debug code outside of the laboratory environment, making it an excellent multi- project software development tool. 13.6 mplab ice high performance universal in-circuit emulator with mplab ide the mplab ice universal in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for picmicro microcontrollers (mcus). software control of the mplab ice in-circuit emulator is provided by the mplab integrated development environment (ide), which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator sys- tem with enhanced trace, trigger and data monitoring features. interchangeable processor modules allow the system to be easily reconfigured for emulation of differ- ent processors. the universal architecture of the mplab ice in-circuit emulator allows expansion to support new picmicro microcontrollers. the mplab ice in-circuit emulator system has been designed as a real-time emulation system, with advanced features that are generally found on more expensive development tools. the pc platform and microsoft ? windows environment were chosen to best make these features available to you, the end user. 13.7 icepic in-circuit emulator the icepic low cost, in-circuit emulator is a solution for the microchip technology pic16c5x, pic16c6x, pic16c7x and pic16cxxx families of 8-bit one- time-programmable (otp) microcontrollers. the mod- ular system can support different subsets of pic16c5x or pic16cxxx products through the use of inter- changeable personality modules, or daughter boards. the emulator is capable of emulating without target application circuitry being present.
? 2006 microchip technology inc. ds30221c-page 113 pic16f872 13.8 mplab icd in-circuit debugger microchip's in-circuit debugger, mplab icd, is a pow- erful, low cost, run-time development tool. this tool is based on the flash picmicro mcus and can be used to develop for this and other picmicro microcontrollers. the mplab icd utilizes the in-circuit debugging capa- bility built into the flash devices. this feature, along with microchip's in-circuit serial programming tm proto- col, offers cost-effective in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by watch- ing variables, single-stepping and setting break points. running at full speed enables testing hardware in real- time. 13.9 pro mate ii universal device programmer the pro mate ii universal device programmer is a full-featured programmer, capable of operating in stand-alone mode, as well as pc-hosted mode. the pro mate ii device programmer is ce compliant. the pro mate ii device programmer has program- mable v dd and v pp supplies, which allow it to verify programmed memory at v dd min and v dd max for max- imum reliability. it has an lcd display for instructions and error messages, keys to enter commands and a modular detachable socket assembly to support various package types. in stand-alone mode, the pro mate ii device programmer can read, verify, or program picmicro devices. it can also set code protection in this mode. 13.10 picstart plus entry level development programmer the picstart plus development programmer is an easy-to-use, low cost, prototype programmer. it con- nects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer sup- ports all picmicro devices with up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 13.11 picdem 1 low cost picmicro demonstration board the picdem 1 demonstration board is a simple board which demonstrates the capabilities of several of microchip?s microcontrollers. the microcontrollers sup- ported are: pic16c5x (pic16c54 to pic16c58a), pic16c61, pic16c62x, pic16c71, pic16c8x, pic17c42, pic17c43 and pic17c44. all necessary hardware and software is included to run basic demo programs. the user can program the sample microcon- trollers provided with the picdem 1 demonstration board on a pro mate ii device programmer, or a picstart plus development programmer, and easily test firmware. the user can also connect the picdem 1 demonstration board to the mplab ice in- circuit emulator and download the firmware to the emu- lator for testing. a prototype area is available for the user to build some additional hardware and connect it to the microcontroller socket(s). some of the features include an rs-232 interface, a potentiometer for simu- lated analog input, push button switches and eight leds connected to portb. 13.12 picdem 2 low cost pic16cxx demonstration board the picdem 2 demonstration board is a simple dem- onstration board that supports the pic16c62, pic16c64, pic16c65, pic16c73 and pic16c74 microcontrollers. all the necessary hardware and soft- ware is included to run the basic demonstration pro- grams. the user can program the sample microcontrollers provided with the picdem 2 demon- stration board on a pro mate ii device programmer, or a picstart plus development programmer, and easily test firmware. the mplab ice in-circuit emula- tor may also be used with the picdem 2 demonstration board to test firmware. a prototype area has been pro- vided to the user for adding additional hardware and connecting it to the microcontroller socket(s). some of the features include a rs-232 interface, push button switches, a potentiometer for simulated analog input, a serial eeprom to demonstrate usage of the i 2 c tm bus and separate headers for connection to an lcd module and a keypad.
pic16f872 ds30221c-page 114 ? 2006 microchip technology inc. 13.13 picdem 3 low cost pic16cxxx demonstration board the picdem 3 demonstration board is a simple dem- onstration board that supports the pic16c923 and pic16c924 in the plcc package. it will also support future 44-pin plcc microcontrollers with an lcd mod- ule. all the necessary hardware and software is included to run the basic demonstration programs. the user can program the sample microcontrollers pro- vided with the picdem 3 demonstration board on a pro mate ii device programmer, or a picstart plus development programmer with an adapter socket, and easily test firmware. the mplab ice in-circuit emula- tor may also be used with the picdem 3 demonstration board to test firmware. a prototype area has been pro- vided to the user for adding hardware and connecting it to the microcontroller socket(s). some of the features include a rs-232 interface, push button switches, a potentiometer for simulated analog input, a thermistor and separate headers for connection to an external lcd module and a keypad. also provided on the picdem 3 demonstration board is a lcd panel, with 4 commons and 12 segments, that is capable of display- ing time, temperature and day of the week. the picdem 3 demonstration board provides an additional rs-232 interface and windows software for showing the demultiplexed lcd signals on a pc. a simple serial interface allows the user to construct a hardware demultiplexer for the lcd signals. 13.14 picdem 17 demonstration board the picdem 17 demonstration board is an evaluation board that demonstrates the capabilities of several microchip microcontrollers, including pic17c752, pic17c756a, pic17c762 and pic17c766. all neces- sary hardware is included to run basic demo programs, which are supplied on a 3.5-inch disk. a programmed sample is included and the user may erase it and program it with the other sample programs using the pro mate ii device programmer, or the picstart plus development programmer, and easily debug and test the sample code. in addition, the picdem 17 dem- onstration board supports downloading of programs to and executing out of external flash memory on board. the picdem 17 demonstration board is also usable with the mplab ice in-circuit emulator, or the picmaster emulator and all of the sample programs can be run and modified using either emulator. addition- ally, a generous prototype area is available for user hardware. 13.15 k ee l oq evaluation and programming tools k ee l oq evaluation and programming tools support microchip?s hcs secure data products. the hcs eval- uation kit includes a lcd display to show changing codes, a decoder to decode transmissions and a pro- gramming interface to program test transmitters.
? 2006 microchip technology inc. ds30221c-page 115 pic16f872 table 13-1: development tools from microchip pic12cxxx pic14000 pic16c5x pic16c6x pic16cxxx pic16f62x pic16c7x pic16c7xx pic16c8x pic16f8xx pic16c9xx pic17c4x pic17c7xx pic18cxx2 pic18fxxx 24cxx/ 25cxx/ 93cxx hcsxxx mcrfxxx mcp2510 software tools mplab ? integrated development environment !!!!!!!!!!!!!!! mplab ? c17 c compiler !! mplab ? c18 c compiler !! mpasm tm assembler/ mplink tm object linker !!!!!!!!!!!!!!! ! ! emulators mplab ? ice in-circuit emulator !!! ! !! ** !!!!!!!!! icepic tm in-circuit emulator ! !!! !!! ! debugger mplab ? icd in-circuit debugger ! * ! * !! programmers picstart ? plus entry level development programmer !!! ! !! ** !!!!!!!!! pro mate ? ii universal device programmer !!! ! !! ** !!!!!!!!! ! ! demo boards and eval kits picdem tm 1 demonstration board !!! ? !! picdem tm 2 demonstration board ! ? ! ? !! picdem tm 3 demonstration board ! picdem tm 14a demonstration board ! picdem tm 17 demonstration board ! k ee l oq ? evaluation kit ! k ee l oq ? transponder kit ! microid tm programmer?s kit ! 125 khz microid tm developer?s kit ! 125 khz anticollision microid tm developer?s kit ! 13.56 mhz anticollision microid tm developer?s kit ! mcp2510 can developer?s kit ! * contact the microchip technology inc. web site at www.microchip.com for information on how to use the mplab ? icd in-circuit debugger (dv164001) with pic16c62, 63, 64, 65, 72, 73, 74, 76, 77. ** contact microchip technology inc. for availability date. ? development tool is available on select devices.
pic16f872 ds30221c-page 116 ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. ds30221c-page 117 pic16f872 14.0 electrical characteristics absolute maximum ratings ? ambient temperature under bias................................................................................................. ............... .-55 to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on any pin with respect to v ss (except v dd , mclr . and ra4) ......................................... -0.3v to (v dd + 0.3v) voltage on v dd with respect to v ss ............................................................................................................ -0.3 to +7.5v voltage on mclr with respect to v ss (note 2) .................................................................................................0 to +14v voltage on ra4 with respect to vss ............................................................................................. .....................0 to +8.5v total power dissipation (note 1) ............................................................................................................................... 1.0w maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ..................................................................................................................... 20 ma output clamp current, i ok (v o < 0 or v o > v dd ) ............................................................................................................. 20 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by porta and portb....................................................................................................200 ma maximum current sourced by porta and portb ..................................................................................... .........200 ma maximum current sunk by portc .................................................................................................. .....................200 ma maximum current sourced by portc ............................................................................................... ...................200 ma note 1: power dissipation is calculated as follows: pdis = v dd x {i dd - i oh } + {(v dd - v oh ) x i oh } + (v o l x i ol ) 2: voltage spikes below v ss at the mclr pin, inducing currents greater than 80 ma, may cause latchup. thus, a series resistor of 50-100 should be used when applying a ?low? level to the mclr pin, rather than pulling this pin directly to v ss . ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic16f872 ds30221c-page 118 ? 2006 microchip technology inc. figure 14-1: pic16f872 voltage- frequency graph figure 14-2: pic16lf872 voltage-frequency graph frequency voltage 6.0 v 5.5 v 4.5 v 4.0 v 2.0 v 20 mhz 5.0 v 3.5 v 3.0 v 2.5 v frequency voltage 6.0 v 5.5 v 4.5 v 4.0 v 2.0 v 5.0 v 3.5 v 3.0 v 2.5 v equation 1: f max = (6.0 mhz/v) (v ddappmin - 2.0v) + 4 mhz; v ddappmin = 2.2v - 3.0v note 1: v ddappmin is the minimum voltage of the picmicro ? device in the application. 4 mhz 10 mhz note 2: f max has a maximum frequency of 10 mhz. 20 mhz equation 2: f max = (10.0 mhz/v) (v ddappmin - 3.0v) + 10 mhz; v ddappmin = 3.0v - 4.0v equation 1 equation 2 2.2 v
? 2006 microchip technology inc. ds30221c-page 119 pic16f872 14.1 dc characteristics: pic16f872 (commercial, industrial) pic16lf872 (commercial, industrial) pic16lf872 (commercial, industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial 0c t a +70c for commercial pic16f872 (commercial, industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial 0c t a +70c for commercial param no. symbol characteristic/ device min typ? max units conditions v dd supply voltage d001 pic16lf872 2.2 ? 5.5 v lp,xt,rc osc configuration (dc to 4 mhz) d001 pic16f872 4.0 ? 5.5 v lp, xt, rc osc configuration d001a pic16lf872 4.5 5.5 v hs osc configuration d001a pic16f872 v bor 5.5 v bor enabled, f max = 14 mhz (7) d002 v dr ram data retention voltage (1) ?1.5? v d003 v por v dd start voltage to ensure internal power-on reset signal ?v ss ? v see section on power-on reset for details d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section on power-on reset for details d005 v bor brown-out reset voltage 3.7 4.0 4.35 v boden bit in configuration word enabled i dd supply current (2,5) d010 pic16lf872 ? 0.6 2.0 ma xt, rc osc configuration f osc = 4 mhz, v dd = 3.0v d010 pic16f872 ? 1.6 4 ma rc osc configurations f osc = 4 mhz, v dd = 5.5v d010a pic16lf872 ? 20 35 a lp osc configuration f osc = 32 khz, v dd = 3.0v, wdt disabled d013 pic16f872 ? 7 15 ma hs osc configuration, f osc = 20 mhz, v dd = 5.5v legend: rows with standard voltage device data only are shaded for improved readability. ? data is ?typ? column is at 5v, 25c, unless otherwise stated. these parameters are for design guidance only, and are not tested. note 1: this is the limit to which v dd can be lowered without losing ram data. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd mclr = v dd ; wdt enabled/disabled as specified. 3: the power-down current in sleep mode does not depend on the oscillator type. power-down current is mea- sured with the part in sleep mode, with all i/o pins in hi-impedance state and tied to v dd and v ss . 4: for rc osc configuration, current through r ext is not included. the current through the resistor can be esti- mated by the formula ir = v dd /2r ext (ma) with r ext in kohm. 5: timer1 oscillator (when enabled) adds approximately 20 a to the specification. this value is from character- ization and is for design guidance only. this is not tested. 6: the current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. 7: when bor is enabled, the device will operate correctly until the v bor voltage trip point is reached.
pic16f872 ds30221c-page 120 ? 2006 microchip technology inc. d015 i bor brown-out reset current (6) ?85200 a bor enabled, v dd = 5.0v i pd power-down current (3,5) d020 pic16lf872 ? 7.5 30 av dd = 3.0v, wdt enabled, -40 c to +85 c d020 pic16f872 ? 10.5 42 a v dd = 4.0v, wdt enabled, -40 c to +85 c d021 pic16lf872 ? 0.9 5 av dd = 3.0v, wdt disabled, 0 c to +70 c d021 pic16f872 ? 1.5 16 a v dd = 4.0v, wdt disabled, -40 c to +85 c d021a pic16lf872 0.9 5 av dd = 3.0v, wdt disabled, -40 c to +85 c d021a pic16f872 1.5 19 a v dd = 4.0v, wdt disabled, -40 c to +85 c d023 i bor brown-out reset current (6) ?85200 a bor enabled, v dd = 5.0v 14.1 dc characteristics: pic16f872 (commercial, industrial) pic16lf872 (commercial, industrial) (continued) pic16lf872 (commercial, industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial 0c t a +70c for commercial pic16f872 (commercial, industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial 0c t a +70c for commercial param no. symbol characteristic/ device min typ? max units conditions legend: rows with standard voltage device data only are shaded for improved readability. ? data is ?typ? column is at 5v, 25c, unless otherwise stated. these parameters are for design guidance only, and are not tested. note 1: this is the limit to which v dd can be lowered without losing ram data. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd mclr = v dd ; wdt enabled/disabled as specified. 3: the power-down current in sleep mode does not depend on the oscillator type. power-down current is mea- sured with the part in sleep mode, with all i/o pins in hi-impedance state and tied to v dd and v ss . 4: for rc osc configuration, current through r ext is not included. the current through the resistor can be esti- mated by the formula ir = v dd /2r ext (ma) with r ext in kohm. 5: timer1 oscillator (when enabled) adds approximately 20 a to the specification. this value is from character- ization and is for design guidance only. this is not tested. 6: the current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. 7: when bor is enabled, the device will operate correctly until the v bor voltage trip point is reached.
? 2006 microchip technology inc. ds30221c-page 121 pic16f872 14.2 dc characteristics: pic16f872 (commercial, industrial) pic16lf872 (commercial, industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial 0c t a +70c for commercial operating voltage v dd range as described in dc specification (section 14.1) param no. sym characteristic min typ? max units conditions v il input low voltage i/o ports: d030 with ttl buffer v ss -0.15v dd v for entire v dd range d030a v ss - 0.8v v 4.5v v dd 5.5v d031 with schmitt trigger buffer v ss -0.2v dd v d032 mclr , osc1 (in rc mode) v ss -0.2v dd v d033 osc1 (in xt, hs and lp modes) v ss -0.3v dd v (note 1) ports rc3 and rc4: d034 with schmitt trigger buffer v ss -0.3v dd v for entire v dd range d034a with smbus -0.5 - 0.6 v for v dd = 4.5 to 5.5v v ih input high voltage i/o ports: - d040 with ttl buffer 2.0 - v dd v4.5v v dd 5.5v d040a 0.25v dd + 0.8v -v dd v for entire v dd range d041 with schmitt trigger buffer 0.8v dd -v dd v for entire v dd range d042 mclr 0.8v dd -v dd v d042a osc1 (xt, hs and lp modes) 0.7v dd -v dd v (note 1) d043 osc1 (in rc mode) 0.9v dd -v dd v ports rc3 and rc4: d044 with schmitt trigger buffer 0.7v dd -v dd v for entire v dd range d044a with smbus 1.4 - 5.5 v for v dd = 4.5 to 5.5v d070 i purb portb weak pull-up current 50 250 400 av dd = 5v, v pin = v ss , -40c to +85c i il input leakage current (2, 3) d060 i/o ports - - 1 avss v pin v dd , pin at hi-impedance d061 mclr , ra4/t0cki - - 5 avss v pin v dd d063 osc1 - - 5 avss v pin v dd , xt, hs and lp osc configuration * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clkin pin is a schmitt trigger input. it is not recommended that the pic16f872 be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
pic16f872 ds30221c-page 122 ? 2006 microchip technology inc. v ol output low voltage d080 i/o ports - - 0.6 v i ol = 8.5 ma, v dd = 4.5v, -40 c to +85 c d083 osc2/clkout (rc osc config) - - 0.6 v i ol = 1.6 ma, v dd = 4.5v, -40 c to +85 c v oh output high voltage d090 i/o ports (3) v dd - 0.7 - - v i oh = -3.0 ma, v dd = 4.5v, -40 c to +85 c d092 osc2/clkout (rc osc config) v dd - 0.7 - - v i oh = -1.3 ma, v dd = 4.5v, -40 c to +85 c d150* v od open drain high voltage - - 8.5 v ra4 pin capacitive loading specs on output pins d100 c osc2 osc2 pin - - 15 pf in xt, hs and lp modes when external clock is used to drive osc1 d101 d102 c io c b all i/o pins and osc2 (rc mode) scl, sda (i 2 c mode) - - - - 50 400 pf pf data eeprom memory d120 e d endurance 100k - - e/w 25 c at 5v d121 v drw v dd for read/write v min - 5.5 v using eecon to read/write v min = min. operating voltage d122 t dew erase/write cycle time - 4 8 ms program flash memory d130 e p endurance 1000 - - e/w 25 c at 5v d131 v pr v dd for read v min - 5.5 v vmin = min operating voltage d132a v dd for erase/write v min - 5.5 v using eecon to read/write, v min = min. operating voltage d133 t pew erase/write cycle time - 4 8 ms 14.2 dc characteristics: pic16f872 (commercial, industrial) pic16lf872 (commercial, industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial 0c t a +70c for commercial operating voltage v dd range as described in dc specification (section 14.1) param no. sym characteristic min typ? max units conditions * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clkin pin is a schmitt trigger input. it is not recommended that the pic16f872 be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
? 2006 microchip technology inc. ds30221c-page 123 pic16f872 14.3 dc characteristics: pic16f872 (extended) pic16f872 (extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. symbol characteristic/ device min typ? max units conditions v dd supply voltage d001 4.0 ? 5.5 v lp, xt, rc osc configuration d001a 4.5 5.5 v hs osc configuration d001a v bor 5.5 v bor enabled, f max = 14 mhz (7) d002 v dr ram data retention voltage (1) ?1.5? v d003 v por v dd start voltage to ensure internal power-on reset signal ?v ss ? v see section on power-on reset for details d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section on power-on reset for details d005 v bor brown-out reset voltage 3.7 4.0 4.35 v boden bit in configuration word enabled i dd supply current (2,5) d010 ? 1.6 4 ma rc osc configurations f osc = 4 mhz, v dd = 5.5v d013 ? 7 15 ma hs osc configuration, f osc = 20 mh z , v dd = 5.5v d015 i bor brown-out reset current (6) ? 85 200 a bor enabled, v dd = 5.0v i pd power-down current (3,5) d020a 10.5 60 av dd = 4.0v, wdt enabled d021b 1.5 30 av dd = 4.0v, wdt disabled d023 i bor brown-out reset current (6) ? 85 200 a bor enabled, v dd = 5.0v ? data in ?typ? column is at 5v, 25c, unless otherwise stated. these parameters are for design guidance only, and are not tested. note 1: this is the limit to which v dd can be lowered without losing ram data. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd mclr = v dd ; wdt enabled/disabled as specified. 3: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in hi-impedance state and tied to v dd and v ss . 4: for rc osc configuration, current through r ext is not included. the current through the resistor can be esti- mated by the formula ir = v dd /2r ext (ma) with r ext in kohm. 5: timer1 oscillator (when enabled) adds approximately 20 a to the specification. this value is from charac- terization and is for design guidance only. this is not tested. 6: the current is the additional current consumed when this peripheral is enabled. this current should be added to the base i dd or i pd measurement. 7: when bor is enabled, the device will operate correctly until the v bor voltage trip point is reached.
pic16f872 ds30221c-page 124 ? 2006 microchip technology inc. 14.4 dc characteristics: pic16f872 (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c operating voltage v dd range as described in dc specification (section 14.1) param no. sym characteristic min typ? max units conditions v il input low voltage i/o ports: d030 with ttl buffer vss - 0.15v dd v for entire v dd range d030a vss - 0.8v v 4.5v v dd 5.5v d031 with schmitt trigger buffer vss - 0.2v dd v d032 mclr , osc1 (in rc mode) v ss -0.2v dd v d033 osc1 (in xt, hs and lp modes) v ss -0.3v dd v (note1) ports rc3 and rc4: d034 with schmitt trigger buffer vss - 0.3v dd v for entire v dd range d034a with smbus -0.5 - 0.6 v for v dd = 4.5 to 5.5v v ih input high voltage i/o ports: - d040 with ttl buffer 2.0 - v dd v4.5v v dd 5.5v d040a 0.25v dd + 0.8v -v dd v for entire v dd range d041 with schmitt trigger buffer 0.8v dd -v dd v for entire v dd range d042 mclr 0.8v dd -v dd v d042a osc1 (xt, hs and lp modes) 0.7v dd -v dd v (note1) d043 osc1 (in rc mode) 0.9v dd -v dd v ports rc3 and rc4: d044 with schmitt trigger buffer 0.7v dd -v dd v for entire v dd range d044a with smbus 1.4 - 5.5 v for v dd = 4.5 to 5.5v d070a i purb portb weak pull-up current 50 300 500 av dd = 5v, v pin = v ss , i il input leakage current (2, 3) d060 i/o ports - - 1 a vss v pin v dd , pin at hi-impedance d061 mclr , ra4/t0cki - - 5 a vss v pin v dd d063 osc1 - - 5 a vss v pin v dd , xt, hs and lp osc configuration * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clkin pin is a schmitt trigger input. it is not recommended that the pic16f872 be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
? 2006 microchip technology inc. ds30221c-page 125 pic16f872 v ol output low voltage d080a i/o ports 0.6 v i ol =2.5 ma, v dd = 4.5v d083a osc2/clkout (rc osc config) 0.6 v i ol = 1.2 ma, v dd = 4.5v v oh output high voltage d090a i/o ports (3) v dd - 0.7 - - v i oh = -2.5 ma, v dd = 4.5v d092a osc2/clkout (rc osc config) v dd - 0.7 - - v i oh = -1.0 ma, v dd = 4.5v d150* v od open drain high voltage - - 8.5 v ra4 pin capacitive loading specs on output pins d100 c osc2 osc2 pin - - 15 pf in xt, hs and lp modes when external clock is used to drive osc1 d101 d102 c io c b all i/o pins and osc2 (rc mode) scl, sda (i 2 c mode) - - - - 50 400 pf pf data eeprom memory d120 e d endurance 100k - - e/w 25 c at 5v d121 v drw v dd for read/write v min - 5.5 v using eecon to read/write v min = min. operating voltage d122 t dew erase/write cycle time - 4 8 ms program flash memory d130 e p endurance 1000 - - e/w 25 c at 5v d131 v pr v dd for read v min -5.5vv min = min. operating voltage d132a v dd for erase/write v min - 5.5 v using eecon to read/write, v min = min. operating voltage d133 t pew erase/write cycle time - 4 8 ms 14.4 dc characteristics: pic16f872 (extended) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c operating voltage v dd range as described in dc specification (section 14.1) param no. sym characteristic min typ? max units conditions * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1/clkin pin is a schmitt trigger input. it is not recommended that the pic16f872 be driven with external clock in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin.
pic16f872 ds30221c-page 126 ? 2006 microchip technology inc. 14.5 timing parameter symbology the timing parameter symbols have been created fol- lowing one of the following formats: figure 14-3: load conditions 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clkout rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s ffall pperiod hhigh rrise i invalid (hi-impedance) v valid l low z hi-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition v dd /2 c l r l pin pin v ss v ss c l r l =464 c l = 50 pf for all pins except osc2, but including portd and porte outputs as ports 15 pf for osc2 output load condition 1 load condition 2
? 2006 microchip technology inc. ds30221c-page 127 pic16f872 figure 14-4: external clock timing osc1 clkout q4 q1 q2 q3 q4 q1 1 2 3 3 4 4 table 14-1: external clock timing requirements parameter no. sym characteristic min typ? max units conditions f osc external clkin frequency (note 1) dc ? 4 mhz xt and rc osc mode dc ? 4 mhz hs osc mode (-04) dc ? 20 mhz hs osc mode (-20) dc ? 200 khz lp osc mode oscillator frequency (note 1) dc ? 4 mhz rc osc mode 0.1 ? 4 mhz xt osc mode 4 5 ? ? 20 200 mhz khz hs osc mode lp osc mode 1t osc external clkin period (note 1) 250 ? ? ns xt and rc osc mode 250 ? ? ns hs osc mode (-04) 50 ? ? ns hs osc mode (-20) 5? ? slp osc mode oscillator period (note 1) 250 ? ? ns rc osc mode 250 ? 10,000 ns xt osc mode 250 ? 250 ns hs osc mode (-04) 50 ? 250 ns hs osc mode (-20) 5? ? slp osc mode 2t cy instruction cycle time (note 1) 200 t cy dc ns t cy = 4/f osc 3 tosl, to sh external clock in (osc1) high or low time 100 ? ? ns xt oscillator 2.5 ? ? s lp oscillator 15 ? ? ns hs oscillator 4tosr, to sf external clock in (osc1) rise or fall time ? ? 25 ns xt oscillator ? ? 50 ns lp oscillator ? ? 15 ns hs oscillator ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time-base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at "min." values with an external clock applied to the osc1/clkin pin. when an external clock input is used, the "max." cycle time limit is "dc" (no clock) for all devices.
pic16f872 ds30221c-page 128 ? 2006 microchip technology inc. figure 14-5: clko ut and i/o timing table 14-2: clkout and i/o timing requirements note: refer to figure 14-3 for load conditions. osc1 clkout i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value param no. symbol characteristic min typ? max units conditions 10* tosh2ckl osc1 to clkout ? 75 200 ns (note 1) 11* tosh2ckh osc1 to clkout ? 75 200 ns (note 1) 12* tckr clkout rise time ? 35 100 ns (note 1) 13* tckf clkout fall time ? 35 100 ns (note 1) 14* tckl2iov clkout to port out valid ? ? 0.5t cy + 20 ns (note 1) 15* tiov2ckh port in valid before clkout t osc + 200 ? ? ns (note 1) 16* tckh2ioi port in hold after clkout 0??ns (note 1) 17* tosh2iov osc1 (q1 cycle) to port out valid ? 100 255 ns 18* tosh2ioi osc1 (q2 cycle) to port input invalid (i/o in hold time) standard ( f ) 100 ? ? ns extended ( lf ) 200 ? ? ns 19* tiov2osh port input valid to osc1 (i/o in setup time) 0 ? ? ns 20* t io r port output rise time standard ( f ) ? 10 40 ns extended ( lf ) ? ? 145 ns 21* t io f port output fall time standard ( f ) ? 10 40 ns extended ( lf ) ? ? 145 ns 22??* t inp int pin high or low time t cy ??ns 23??* t rbp rb7:rb4 change int high or low time t cy ??ns * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise st ated. these parameters are for design guidance only and are not tested. ?? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in rc mode, where clkout output is 4 x t osc .
? 2006 microchip technology inc. ds30221c-page 129 pic16f872 figure 14-6: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 14-7: brown-out reset timing table 14-3: reset, watchdog timer, oscillator start-up timer, power-up timer, and brown-out reset requirements v dd mclr internal por pwrt time-out osc time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 14-3 for load conditions. v dd v bor 35 parameter no. symbol characteristic min typ? max units conditions 30 t mc lmclr pulse width (low) 2 ? ? sv dd = 5v, -40c to +85c 31* t wdt watchdog timer time-out period (no prescaler) 71833msv dd = 5v, -40c to +85c 32 t ost oscillation start-up timer period ? 1024 t osc ??t osc = osc1 period 33* t pwrt power up timer period 28 72 132 ms v dd = 5v, -40c to +85c 34 t ioz i/o hi-impedance from mclr low or watchdog timer reset ??2.1 s 35 t bor brown-out reset pulse width 100 ? ? sv dd v bor (d005) * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise st ated. these parameters are for design guidance only and are not tested.
pic16f872 ds30221c-page 130 ? 2006 microchip technology inc. figure 14-8: timer0 and timer1 external clock timings table 14-4: timer0 and timer1 external clock requirements param no. symbol characteristic min typ? max units conditions 40* tt0h t0cki high pulse width no prescaler 0.5t cy + 20 ? ? ns must also meet parameter 42 with prescaler 10 ? ? ns 41* tt0l t0cki low pulse width no prescaler 0.5t cy + 20 ? ? ns must also meet parameter 42 with prescaler 10 ? ? ns 42* tt0p t0cki period no prescaler t cy + 40 ? ? ns with prescaler greater of: 20 or t cy + 40 n ? ? ns n = prescale value (2, 4,..., 256) 45* tt1h t1cki high time synchronous, prescaler = 1 0.5t cy + 20 ? ? ns must also meet parameter 47 synchronous, prescaler = 2,4,8 standard( f )15??ns extended( lf )25 ??ns asynchronous standard( f )30??ns extended( lf )50 ??ns 46* tt1l t1cki low time synchronous, prescaler = 1 0.5t cy + 20 ? ? ns must also meet parameter 47 synchronous, prescaler = 2,4,8 standard( f )15??ns extended( lf )25 ??ns asynchronous standard( f )30??ns extended( lf )50 ??ns 47* tt1p t1cki input period synchronous standard( f ) greater of: 30 or t cy + 40 n ? ? ns n = prescale value (1, 2, 4, 8) extended( lf ) greater of: 50 or t cy + 40 n n = prescale value (1, 2, 4, 8) asynchronous standard( f )60??ns extended( lf ) 100 ? ? ns ft1 timer1 oscillator input frequency range (oscillator enabled by setting bit t1oscen) dc ? 200 khz 48 tckeztmr1 delay from external clock edge to timer increment 2t osc ?7t osc ? * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note: refer to figure 14-3 for load conditions. 46 47 45 48 41 42 40 ra4/t0cki rc0/t1oso/t1cki tmr0 or tmr1
? 2006 microchip technology inc. ds30221c-page 131 pic16f872 figure 14-9: capture/compare/pwm timings table 14-5: capture/compare/pwm requirements note: refer to figure 14-3 for load conditions. and rc2/ccp1 (capture mode) 50 51 52 53 54 rc1/t1osi/ccp2 and rc2/ccp1 (compare or pwm mode) rc1/t1osi/ccp2 param no. sym characteristic min typ? max units conditions 50* tccl ccp1 input low time no prescaler 0.5t cy + 20 ? ? ns with prescaler standard( f )10??ns extended( lf )20??ns 51* tcch ccp1 input high time no prescaler 0.5t cy + 20 ? ? ns with prescaler standard( f )10??ns extended( lf )20??ns 52* tccp ccp1 input period 3t cy + 40 n ? ? ns n = prescale value (1,4 or 16) 53* tccr ccp1 output rise time standard( f ) ? 10 25 ns extended( lf ) ? 25 50 ns 54* tccf ccp1 output fall time standard( f ) ? 10 25 ns extended( lf ) ? 25 45 ns * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested.
pic16f872 ds30221c-page 132 ? 2006 microchip technology inc. figure 14-10: spi master mo de timing (cke = 0, smp = 0) figure 14-11: spi master mo de timing (cke = 1, smp = 1) ss sck (ckp = 0) sck (ckp = 1) sdo sdi 70 71 72 73 74 75, 76 78 79 80 79 78 msb lsb bit6 - - - - - -1 msb in lsb in bit6 - - - -1 note: refer to figure 14-3 for load conditions. ss sck (ckp = 0) sck (ckp = 1) sdo sdi 81 71 72 74 75, 76 78 80 msb 79 73 msb in bit6 - - - - - -1 lsb in bit6 - - - -1 lsb note: refer to figure 14-3 for load conditions.
? 2006 microchip technology inc. ds30221c-page 133 pic16f872 figure 14-12: spi slave mode timing (cke = 0) figure 14-13: spi slave mode timing (cke = 1) ss sck (ckp = 0) sck (ckp = 1) sdo sdi 70 71 72 73 74 75, 76 77 78 79 80 79 78 sdi msb lsb bit6 - - - - - -1 msb in bit6 - - - -1 lsb in 83 note: refer to figure 14-3 for load conditions. ss sck (ckp = 0) sck (ckp = 1) sdo sdi 70 71 72 82 sdi 74 75, 76 msb bit6 - - - - - -1 lsb 77 msb in bit6 - - - -1 lsb in 80 83 note: refer to figure 14-3 for load conditions.
pic16f872 ds30221c-page 134 ? 2006 microchip technology inc. table 14-6: spi mode requirements figure 14-14: i 2 c bus start/stop bits timing table 14-7: i 2 c bus start/stop bits requirements param no. symbol characteristic min typ? max units conditions 70* tssl2sch, tssl2scl ss to sck or sck input t cy ??ns 71* tsch sck input high time (slave mode) t cy + 20 ? ? ns 72* tscl sck input low time (slave mode) t cy + 20 ? ? ns 73* tdiv2sch, tdiv2scl setup time of sdi data input to sck edge 100 ? ? ns 74* tsch2dil, tscl2dil hold time of sdi data input to sck edge 100 ? ? ns 75* tdor sdo data output rise time standard( f ) extended( lf ) ? ? 10 25 25 50 ns ns 76* tdof sdo data output fall time ? 10 25 ns 77* tssh2doz ss to sdo output hi-impedance 10 ? 50 ns 78* tscr sck output rise time (master mode) standard( f ) extended( lf ) ? ? 10 25 25 50 ns ns 79* tscf sck output fall time (master mode) ? 10 25 ns 80* tsch2dov, tscl2dov sdo data output valid after sck edge standard( f ) extended( lf ) ? ? ? ? 50 145 ns 81* tdov2sch, tdov2scl sdo data output setup to sck edge t cy ??ns 82* tssl2dov sdo data output valid after ss edge ? ? 50 ns 83* tsch2ssh, tscl2ssh ss after sck edge 1.5t cy + 40 ? ? ns * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. parameter no. symbol characteristic min typ max units conditions 90 t su : sta start condition 100 khz mode 4700 ? ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? ? 91 t hd : sta start condition 100 khz mode 4000 ? ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? ? 92 t su : sto stop condition 100 khz mode 4700 ? ? ns setup time 400 khz mode 600 ? ? 93 t hd : sto stop condition 100 khz mode 4000 ? ? ns hold time 400 khz mode 600 ? ? note: refer to figure 14-3 for load conditions. 91 93 scl sda start condition stop condition 90 92
? 2006 microchip technology inc. ds30221c-page 135 pic16f872 figure 14-15: i 2 c bus data timing table 14-8: i 2 c bus data requirements param no. sym characteristic min max units conditions 100 t high clock high time 100 khz mode 4.0 ? s device must operate at a mini- mum of 1.5 mhz 400 khz mode 0.6 ? s device must operate at a mini- mum of 10 mhz ssp module 1.5t cy ? 101 t low clock low time 100 khz mode 4.7 ? s device must operate at a mini- mum of 1.5 mhz 400 khz mode 1.3 ? s device must operate at a mini- mum of 10 mhz ssp module 1.5t cy ? 102 t r sda and scl rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1c b 300 ns c b is specified to be from 10 to 400 pf 103 t f sda and scl fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1c b 300 ns c b is specified to be from 10 to 400 pf 90 t su : sta start condition setup time 100 khz mode 4.7 ? s only relevant for repeated start condition 400 khz mode 0.6 ? s 91 t hd : sta start condition hold time 100 khz mode 4.0 ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? s 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 s 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 92 t su : sto stop condition setup time 100 khz mode 4.7 ? s 400 khz mode 0.6 ? s 109 t aa output valid from clock 100 khz mode ? 3500 ns (note 1) 400 khz mode ? ? ns 110 t buf bus free time 100 khz mode 4.7 ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? s c b bus capacitive loading ? 400 pf note 1: as a transmitter, the device must provide this internal mi nimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of scl to avoid unintended generation of start or stop conditions. 2: a fast mode (400 khz) i 2 c bus device can be used in a standard mode (100 khz) i 2 c bus system, but the requirement that t su : dat 250 ns must then be met. this will autom atically be the case if the devic e does not stretc h the low period of the scl signal. if such a device does stretch the low period of the scl signal, it must output the next data bit to the sda line: t r max.+ t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification) before the scl line is released. note: refer to figure 14-3 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 scl sda in sda out
pic16f872 ds30221c-page 136 ? 2006 microchip technology inc. table 14-9: a/d converter characteristics: pic16f872 (commercial, industrial, extended) pic16lf872 (commercial, industrial) param no. sym characteristic min typ? max units conditions a01 n r resolution ? ? 10-bits bit v ref = v dd = 5.12v, v ss v ain v ref a03 e il integral linearity error ? ? < 1 lsb v ref = v dd = 5.12v, v ss v ain v ref a04 e dl differential linearity error ? ? < 1 lsb v ref = v dd = 5.12v, v ss v ain v ref a06 e off offset error ? ? < 2 lsb v ref = v dd = 5.12v, v ss v ain v ref a07 e gn gain error ? ? < 1 lsb v ref = v dd = 5.12v, v ss v ain v ref a10 ? monotonicity ? guaranteed (3) ??v ss v ain v ref a20 v ref reference voltage (v ref + - v ref -) 2.0 ? v dd + 0.3 v absolute minimum electrical spec. to ensure 10-bit accuracy. a21 v ref + reference voltage high av dd - 2.5v av dd + 0.3v v a22 v ref - reference voltage low av ss - 0.3v v ref + - 2.0v v a25 v ain analog input voltage v ss - 0.3v ? v ref + 0.3v v a30 z ain recommended impedance of analog voltage source ? ? 10.0 k a40 i ad a/d conversion current (v dd ) standard ? 220 ? a average current consumption when a/d is on (note 1) . extended ? 90 ? a a50 i ref v ref input current (note 2) 10 ? ? ? 1000 10 a a during v ain acquisition, based on differential of v hold to v ain to charge c hold , see section 10.1. during a/d conversion cycle. * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stat ed. these parameters are for design guidance only and are not tested. note 1: when a/d is off, it will not consume any current other than minor leakage current. the power-down current spec includes any such leakage from the a/d module. 2: v ref current is from ra3 pin or v dd pin, whichever is selected as reference input. 3: the a/d conversion result never dec reases with an increase in the i nput voltage, and has no missing codes.
? 2006 microchip technology inc. ds30221c-page 137 pic16f872 figure 14-16: a/d conversion timing table 14-10: a/d conversion requirements 131 130 132 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data (t osc /2) (1) 987 210 note: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 1 t cy . . . . . . param no. sym characteristic min typ? max units conditions 130 t ad a/d clock period standard( f )1.6?? st osc based, v ref 3.0v extended( lf )3.0?? st osc based, v ref 2.0v standard( f ) 2.0 4.0 6.0 s a/d rc mode extended( lf ) 3.0 6.0 9.0 s a/d rc mode 131 t cnv conversion time (not including s/h time) (note 1) ?12t ad 132 t acq acquisition time (note 2) 10* 40 ? ? ? s s the minimum time is the amplifier settling time. this may be used if the "new" input volt- age has not changed by more than 1 lsb (i.e., 20.0 mv @ 5.12v) from the last sampled voltage (as stated on c hold ). 134 t go q4 to a/d clock start ? t osc /2 ? ? if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. * these parameters are characterized but not tested. ? data in "typ" column is at 5v, 25c unless otherwise stat ed. these parameters are for design guidance only and are not tested. this specification ensured by design. note 1: adres register may be read on the following t cy cycle. 2: see section 10.1 for min. conditions.
pic16f872 ds30221c-page 138 ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. ds30221c-page 139 pic16f872 15.0 dc and ac characteristics graphs and tables ?typical? represents the mean of the distribution at 25 c. ?maximum? or ?minimum? represents (mean + 3 ) or (mean - 3 ) respectively, where is a standard deviation, over the whole temperature range. figure 15-1: typical i dd vs. f osc over v dd (hs mode) figure 15-2: maximum i dd vs. f osc over v dd (hs mode) note: the graphs and tables provided following this note are a statistical summary based on a limited number of samples and are provided for informational purposes only. the performance characteristics listed herein are not tested or guaranteed. in some graphs or tables, the data presented may be outside the specified oper- ating range (e.g., outside specified power supply range) and therefore, outside the warranted range. 0 1 2 3 4 5 6 7 4 6 8 101214161820 f osc (m hz) i dd (ma) 2.5v 2.2v 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0 1 2 3 4 5 6 7 8 4 6 8 101214161820 f osc (m hz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.2v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
pic16f872 ds30221c-page 140 ? 2006 microchip technology inc. figure 15-3: typical i dd vs. f osc over v dd (xt mode) figure 15-4: maximum i dd vs. f osc over v dd (xt mode) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 2.5v 2.2v 3.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 f osc (mhz) i dd (ma) 5.5v 5.0v 4.5v 4.0v 3.5v 2.5v 2.2v 3.0v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
? 2006 microchip technology inc. ds30221c-page 141 pic16f872 figure 15-5: typical i dd vs. f osc over v dd (lp mode) figure 15-6: maximum i dd vs. f osc over v dd (lp mode) 0 10 20 30 40 50 60 70 80 20 30 40 50 60 70 80 90 100 f osc (khz) i dd (ua) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.2v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) i dd ( a) 0 10 20 30 40 50 60 70 80 90 100 110 120 20 30 40 50 60 70 80 90 100 f osc (khz) i dd (ua) 5.5v 5.0v 4.5v 4.0v 3.5v 3.0v 2.5v 2.2v typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) i dd ( a)
pic16f872 ds30221c-page 142 ? 2006 microchip technology inc. figure 15-7: average f osc vs. v dd for various values of r (rc mode, c = 20 pf, 25 c) figure 15-8: average f osc vs. v dd for various values of r (rc mode, c = 100 pf, 25 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 3.3k 5.1k 10k 100k 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 3.3k 5.1k 10k 100k
? 2006 microchip technology inc. ds30221c-page 143 pic16f872 figure 15-9: average f osc vs. v dd for various values of r (rc mode, c = 300 pf, 25 c) figure 15-10: i pd vs. v dd (sleep mode, all peripherals disabled) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) freq (mhz) 3.3k 5.1k 10k 100k 0.01 0.1 1 10 100 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i pd ( a) max (125c) max (85c) typ (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) max (125c) max (85c) typ (25c)
pic16f872 ds30221c-page 144 ? 2006 microchip technology inc. figure 15-11: i bor vs. v dd over temperature figure 15-12: typical and maximum i tmr1 vs. v dd over temperature (-10 c to +70 c, timer1 with oscillator, xtal=32 khz, c1 and c2=50 pf) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i bor (ma) device in sleep device in reset max reset typ reset (25c) max sleep typ sleep (25c) indeterminate state 2.2 typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) note: device current in reset depends on oscillator mode, frequency and circuit. device in reset device in sleep typ sleep (25c) typ reset (25c) max reset max sleep 0 10 20 30 40 50 60 70 80 90 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i tmr1 ( a) typ (25c) max (-10c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) max (-10c) typ (25c)
? 2006 microchip technology inc. ds30221c-page 145 pic16f872 figure 15-13: typical and maximum i wdt vs. v dd over temperature figure 15-14: typical, minimum and maximum wdt period vs. v dd (-40 c to +125 c) 0 2 4 6 8 10 12 14 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) i wdt ( a) typ (25c) max (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) max (125c) typ (25c) 0 5 10 15 20 25 30 35 40 45 50 2.02.53.03.54.04.55.05.5 v dd (v) wdt period (ms) max (85c) min (-40c) typ (25c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) max (85c) typ (25c) min (-40c)
pic16f872 ds30221c-page 146 ? 2006 microchip technology inc. figure 15-15: average wdt period vs. v dd over temperature (-40 c to +125 c) figure 15-16: typical, minimum and maximum v oh vs. i oh (v dd =5v, -40 c to +125 c) 0 5 10 15 20 25 30 35 40 45 50 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) wdt period (ms) 85c 125c 25c -40c 2.2 typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 125c 85c 25c -40c 2.0 2.5 3.0 3.5 4.0 4.5 5.0 0 5 10 15 20 25 i oh (-ma) v oh (v) max (-40c) typ (25c) min (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) max (-40c) typ (25c) min (125c)
? 2006 microchip technology inc. ds30221c-page 147 pic16f872 figure 15-17: typical, minimum and maximum v oh vs. i oh (v dd =3v, -40 c to +125 c) figure 15-18: typical, minimum and maximum v ol vs. i ol (v dd =5v, -40 c to 125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 5 10 15 20 25 i oh (-ma) v oh (v) max (-40c) typ (25c) min (125c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) max (-40c) typ (25c) min (125c) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 0 5 10 15 20 25 i ol (-ma) v ol (v) max (125c) typ (25c) min (-40c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) max (125c) typ (25c) min (-40c)
pic16f872 ds30221c-page 148 ? 2006 microchip technology inc. figure 15-19: typical, minimum and maximum v ol vs. i ol (v dd =3v, -40 c to +125 c) figure 15-20: minimum and maximum v in vs. v dd , (ttl input, -40 c to +125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 0 5 10 15 20 25 i ol (-ma) v ol (v) max (125c) typ (25c) min (-40c) typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) max (125c) typ (25c) min (-40c) 0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) max min typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
? 2006 microchip technology inc. ds30221c-page 149 pic16f872 figure 15-21: minimum and maximum v in vs. v dd (st input, -40 c to +125 c) figure 15-22: minimum and maximum v in vs. v dd (i 2 c input, -40 c to +125 c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) max high max low min high min low typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c) 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 v dd (v) v in (v) max high max low min high min low typical: statistical mean @ 25c maximum: mean + 3 (-40c to 125c) minimum: mean ? 3 (-40c to 125c)
pic16f872 ds30221c-page 150 ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. ds30221c-page 151 pic16f872 16.0 packaging information 16.1 package marking information legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 3 e 28-lead spdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic16f872/sp 0610017 28-lead soic xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx yywwnnn example pic16f872-i/so 0610017 3 e 28-lead ssop xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic16lf872 -i/ss 0610017 3 e
pic16f872 ds30221c-page 152 ? 2006 microchip technology inc. 28-lead skinny plastic dual in-line (sp) ? 300 mil body (pdip) note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 10.92 8.89 8.13 .430 .350 .320 eb overall row spacing 0.56 0.48 0.41 .022 .019 .016 b lower lead width 1.65 1.33 1.02 .065 .053 .040 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.18 .135 .130 .125 l tip to seating plane 35.18 34.67 34.16 1.385 1.365 1.345 d overall length 7.49 7.24 6.99 .295 .285 .275 e1 molded package width 8.26 7.87 7.62 .325 .310 .300 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 3.43 3.30 3.18 .135 .130 .125 a2 molded package thickness 4.06 3.81 3.56 .160 .150 .140 a top to seating plane 2.54 .100 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters inches * units 2 1 d n e1 c eb e p l a2 b b1 a a1 notes: jedec equivalent: mo-095 drawing no. c04-070 * controlling parameter dimension d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per sid e. significant characteristic
? 2006 microchip technology inc. ds30221c-page 153 pic16f872 28-lead plastic small outline (so) ? wide, 300 mil body (soic) note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging foot angle top 048048 15 12 0 15 12 0 mold draft angle bottom 15 12 0 15 12 0 mold draft angle top 0.51 0.42 0.36 .020 .017 .014 b lead width 0.33 0.28 0.23 .013 .011 .009 c lead thickness 1.27 0.84 0.41 .050 .033 .016 l foot length 0.74 0.50 0.25 .029 .020 .010 h chamfer distance 18.08 17.87 17.65 .712 .704 .695 d overall length 7.59 7.49 7.32 .299 .295 .288 e1 molded package width 10.67 10.34 10.01 .420 .407 .394 e overall width 0.30 0.20 0.10 .012 .008 .004 a1 standoff 2.39 2.31 2.24 .094 .091 .088 a2 molded package thickness 2.64 2.50 2.36 .104 .099 .093 a overall height 1.27 .050 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters inches * units 2 1 d p n b e e1 l c 45 h a2 a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per si de. jedec equivalent: ms-013 drawing no. c04-052 significant characteristic
pic16f872 ds30221c-page 154 ? 2006 microchip technology inc. 28-lead plastic shrink small outline (ss) ? 209 mil body, 5.30 mm (ssop) note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging e1 p b n d 2 1 e c l a a1 a2 0.38 - 0.22 .015 - .009 b lead width 8 4 0 8 4 0 foot angle 0.25 - 0.09 .010 - .004 c lead thickness 0.95 0.75 0.55 .037 .030 .022 l foot length 10.50 10.20 9.90 .413 .402 .390 d overall length 5.60 5.30 5.00 .220 .209 .197 e1 molded package width 8.20 7.80 7.49 .323 .307 .295 e overall width - - 0.05 - - .002 a1 standoff 1.85 1.75 1.65 .073 .069 .065 a2 molded package thickness 2.00 - - .079 - - a overall height 0.65 .026 p pitch 28 28 n number of pins max nom min max nom min dimension limits millimeters* inches units dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010" (0.254mm) per s ide. notes: drawing no. c04-073 *controlling parameter revised 1-12-06
? 2006 microchip technology inc. ds30221c-page 155 pic16f872 appendix a: revision histor y appendix b: conversion considerations considerations for converting from previous versions of devices to the ones listed in this data sheet are listed in table b-1. version date revision description a 11/99 this is a new data sheet (pre- liminary). however, these devices are similar to the pic16c72a devices found in the pic16c62b/72a data sheet (ds35008). b 12/01 final version of data sheet. includes dc and ac charac- teristics graphs and updated electrical specifications. c 9/06 packaging diagrams updated. table b-1: conversion considerations characteristic pic16c72a pic16f872 pins 28 28 timers 3 3 interrupts 7 10 communication basic ssp (spi, i 2 c slave) ssp (spi, i 2 c master/slave) frequency 20 mhz 20 mhz a/d 8-bit, 5 channels 10-bit 5 channels ccp 1 1 program memory 2k eprom 2k flash ram 128 bytes 128 bytes eeprom data none 64 bytes other ? in-circuit debugger, low voltage programming
pic16f872 ds30221c-page 156 ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. ds30221c-page 157 pic16f872 index a a/d ..................................................................................... 79 acquisition requirements .......................................... 82 adcon0 register ..................................................... 79 adcon1 register ..................................................... 79 adif bit ..................................................................... 81 adresh register ..................................................... 79 adresl register ...................................................... 79 associated registers and bits ................................... 85 configuring analog port pins .................................... 83 configuring the interrupt ............................................ 81 configuring the module ............................................. 81 conversion clock ...................................................... 83 conversions ............................................................... 84 effects of a reset .................................................... 85 go/done bit ............................................................ 81 internal sampling switch (rss) impedance ............... 82 operation during sleep ........................................... 85 result registers ........................................................ 84 source impedance .................................................... 82 t ad ............................................................................ 83 absolute maximum ratings ............................................. 117 ack pulse .......................................................................... 59 ackdt bit acknowledge data bit (ackdt) ................................ 54 acken bit acknowledge sequence enable bit (acken) ........... 54 acknowledge pulse (ack ) ................................................. 59 ackstat bit acknowledge status bit (ackstat) ......................... 54 ackstat status flag ....................................................... 67 adcon0 register ............................................................... 9 adcon1 register ............................................................. 10 adresh register ............................................................... 9 adresl register .............................................................. 10 analog-to-digital converter. see a/d application notes an552 (implementing wake-up on key stroke) ........ 31 an556 (implementing a table read) ........................ 20 an578 (use of the ssp module in the i 2 c multi-master environment) ........................ 58 assembler mpasm assembler ................................................. 111 b banking, data memory ........................................................ 7 bclif bit ........................................................................... 18 bf bit buffer full status bit (bf) .......................................... 52 bf status flag ............................................................ 67 , 69 block diagrams a/d converter ............................................................ 81 analog input model .................................................... 82 baud rate generator ................................................ 64 capture mode ............................................................ 46 compare mode .......................................................... 47 i 2 c slave mode ......................................................... 58 interrupt logic ............................................................ 97 mssp (spi mode) ..................................................... 55 on-chip reset circuit ................................................ 91 peripheral output override (rc 2:0, 7:5) .................. 33 peripheral output override (rc 4:3) ......................... 33 pic16f872 .................................................................. 4 pwm mode ............................................................... 48 ra3:ra0 and ra5 pins ............................................ 29 ra4/t0cki pin .......................................................... 29 rb3:rb0 pins ........................................................... 31 rb7:rb4 pins ........................................................... 31 rc oscillator mode ................................................... 90 ssp (i 2 c master mode) ............................................ 63 timer0/wdt prescaler .............................................. 35 timer1 ....................................................................... 40 timer2 ....................................................................... 43 watchdog timer ........................................................ 99 bor. see brown-out reset brown-out reset (bor) ................................ 87 , 91 , 92 , 93 bus arbitration ................................................................... 73 bus collision section ...................................................................... 73 bus collision during a repeated start condition ......... 76 bus collision during a start condition .......................... 74 bus collision during a stop condition ............................ 77 bus collision interrupt flag (bclif) .................................. 18 c capture mode ccp pin configuration .............................................. 46 software interrupt ...................................................... 46 timer1 mode selection ............................................. 46 capture/compare/pwm (ccp) ......................................... 45 associated registers ................................................ 47 pwm and timer2 .............................................. 49 capture mode ........................................................... 46 ccp1if ............................................................. 46 prescaler ........................................................... 46 ccp timer resources .............................................. 45 compare mode ......................................................... 47 software interrupt mode .................................... 47 special event trigger ........................................ 47 pwm mode ............................................................... 48 duty cycle ......................................................... 48 example frequencies/ resolutions (table) ........................... 49 pwm period ...................................................... 48 special event trigger and a/d conversions ............. 47 ccp. see capture/compare/pwm ccp1con register ............................................................ 9 ccp1m3:ccp1m0 bits ...................................................... 45 ccp1x bit .......................................................................... 45 ccp1y bit .......................................................................... 45 ccpr1h register .........................................................9 , 45 ccpr1l register ..........................................................9 , 45 cke bit .............................................................................. 52 ckp bit .............................................................................. 53 clock polarity select bit (ckp) ......................................... 53 code examples changing between capture prescalers .................... 46 eeprom data read ................................................ 25 eeprom data write ................................................. 25 flash program read .............................................. 26 flash program write .............................................. 27 indirect addressing ................................................... 21 initializing porta ..................................................... 29 saving status, w and pclath registers ............ 98 code protected operation data eeprom and flash program memory .......... 28
pic16f872 ds30221c-page 158 ? 2006 microchip technology inc. code protection ........................................................ 87 , 101 compare mode ccp pin configuration ............................................... 47 timer1 mode selection .............................................. 47 computed goto ............................................................... 20 configuration bits .............................................................. 87 configuration word ............................................................ 88 conversion considerations .............................................. 155 d d/a bit ................................................................................ 52 data eeprom ................................................................... 23 associated registers ................................................. 28 code protection ......................................................... 28 reading ..................................................................... 25 special functions registers ...................................... 23 spurious write protection .......................................... 27 write verify ................................................................ 27 writing to .................................................................... 25 data memory ....................................................................... 7 bank select (rp1:rp0 bits) ........................................ 7 general purpose register file .................................... 7 register file map ......................................................... 8 special function registers .......................................... 9 data/address bit (d/a ) ...................................................... 52 dc and ac characteristics graphs and tables .............. 139 dc characteristics commercial and industrial ............................... 119?122 extended ............................................................ 123?52 development support ...................................................... 111 device overview .................................................................. 3 direct addressing .............................................................. 21 e eecon1 and eecon2 registers ..................................... 23 eecon1 register .............................................................. 11 eecon2 register .............................................................. 11 electrical characteristics ................................................. 117 equations a/d calculating acquisition time ............................. 82 errata ................................................................................... 2 external clock timing requirements .............................. 127 f firmware instructions ...................................................... 103 flash program memory .................................................. 23 associated registers ................................................. 28 code protection ......................................................... 28 configuration bits and read/write state ................... 28 reading ..................................................................... 26 special function registers ........................................ 23 spurious write protection .......................................... 27 write protection ......................................................... 28 write verify ................................................................ 27 writing to .................................................................... 26 fsr register ................................................................ 9 , 21 g gcen bit general call enable bit (gcen) ................................ 54 general call address support ........................................... 61 i i/o ports ............................................................................ 29 i 2 c bus connection considerations ....................................... 78 sample device configuration .................................... 78 i 2 c mode acknowledge sequence timing ................................ 71 addressing ................................................................ 59 associated registers ................................................. 62 baud rate generator (brg) ..................................... 64 bus arbitration ........................................................... 73 bus collision .............................................................. 73 repeated start condition .............................. 76 start condition .............................................. 74 stop condition ................................................ 77 clock arbitration ........................................................ 72 conditions to not give ack pulse ............................. 59 effects of a reset .............................................62 , 72 general call address support ................................... 61 master mode ............................................................. 63 master mode operation ............................................. 64 master mode reception ............................................ 69 master mode repeated start condition ................ 66 master mode start condition ................................ 65 master mode transmission ....................................... 67 master mode transmit sequence ............................. 64 multi-master communication ..................................... 73 multi-master mode ..................................................... 63 operation ................................................................... 58 slave mode ............................................................... 58 slave reception ........................................................ 59 slave transmission ................................................... 60 sleep operation ................................................62 , 72 sspadd address register ....................................... 58 sspbuf register ...................................................... 58 stop condition timing ............................................. 71 icepic in-circuit emulator .............................................. 112 id locations ..............................................................87 , 101 in-circuit debugger ...................................................87 , 101 in-circuit serial programming (icsp) .......................87 , 102 indf register ...................................................................... 9 indirect addressing ............................................................ 21 fsr register .........................................................7 , 21 instruction format ........................................................... 103 instruction set ................................................................. 103 addlw ................................................................... 105 addwf ................................................................... 105 andlw ................................................................... 105 andwf ................................................................... 105 bcf ......................................................................... 105 bsf ......................................................................... 105 btfsc ..................................................................... 105 btfss ..................................................................... 105 call ....................................................................... 106 clrf ....................................................................... 106 clrw ...................................................................... 106 clrwdt ................................................................. 106 comf ...................................................................... 106 decf ....................................................................... 106 decfsz .................................................................. 107 goto ...................................................................... 107 incf ........................................................................ 107 incfsz ................................................................... 107 iorlw ..................................................................... 107 iorwf .................................................................... 107
? 2006 microchip technology inc. ds30221c-page 159 pic16f872 movf ...................................................................... 108 movlw ................................................................... 108 movwf ................................................................... 108 nop ......................................................................... 108 retfie .................................................................... 108 retlw .................................................................... 108 return .................................................................. 109 rlf .......................................................................... 109 rrf ......................................................................... 109 sleep ..................................................................... 109 sublw .................................................................... 109 subwf .................................................................... 109 swapf .................................................................... 110 xorlw ................................................................... 110 xorwf ................................................................... 110 summary table ....................................................... 104 int interrupt (rb0/int). see interrupt sources intcon register .......................................................... 9 , 14 gie bit ....................................................................... 14 inte bit ..................................................................... 14 intf bit ..................................................................... 14 peie bit ..................................................................... 14 rbie bit ..................................................................... 14 rbif bit .............................................................. 14 , 31 tmr0ie bit ................................................................ 14 tmr0if bit ................................................................ 14 inter-integrated circuit (i 2 c) .............................................. 51 internal sampling switch (rss) impedance ....................... 82 interrupt sources ........................................................ 87 , 97 interrupt-on-change (rb7:rb4 ) ............................... 31 rb0/int pin, external ............................................... 98 tmr0 overflow .......................................................... 98 interrupts bus collision interrupt ............................................... 18 synchronous serial port interrupt ............................. 16 interrupts, context saving during ...................................... 98 interrupts, enable bits global interrupt enable (gie bit) ............................... 97 interrupt-on-change (rb7:rb4) enable (rbie bit) .................................................. 98 interrupts, flag bits interrupt-on-change (rb7:rb4) flag (rbif bit) ............................................ 31 , 98 tmr0 overflow flag (tmr0if bit) ............................ 98 k k ee l oq evaluation and programming tools ................... 114 l load conditions ............................................................... 126 loading of pc .................................................................... 20 low voltage icsp programming ..................................... 102 low voltage in-circuit serial programming ....................... 87 m master clear (mclr ) mclr reset, normal operation .........................91 , 93 mclr reset, sleep ..........................................91 , 93 master synchronous serial port. see mssp mclr /v pp pin ..................................................................... 5 memory organization .......................................................... 7 data memory ............................................................... 7 program memory ........................................................ 7 mplab c17 and mplab c18 c compilers .................... 111 mplab icd in-circuit debugger ..................................... 113 mplab ice high performance universal in-circuit emulator with mplab ide ...................................... 112 mplab integrated development environment software ............................................. 111 mplink object linker/mplib object librarian ............... 112 mssp ................................................................................ 51 i 2 c operation ............................................................ 58 overflow detect bit (sspov) .................................... 59 special function registers sspcon ........................................................... 51 sspcon2 ......................................................... 51 sspstat .......................................................... 51 spi master mode ...................................................... 55 spi mode .................................................................. 55 spi slave mode ........................................................ 56 sspadd ................................................................... 59 sspadd register ..................................................... 58 sspbuf .................................................................... 55 sspbuf register ..................................................... 58 sspsr ................................................................55 , 59 sspstat register ................................................... 58 multi-master communication ............................................. 73 o opcode field descriptions ........................................... 103 option_reg register ..............................................10 , 13 intedg bit ............................................................... 13 ps2:ps0 bits ............................................................. 13 psa bit ...................................................................... 13 rbpu bit ................................................................... 13 t0cs bit .................................................................... 13 t0se bit .................................................................... 13 osc1/clki pin ................................................................... 5 osc2/clko pin .................................................................. 5 oscillator configuration hs .......................................................................89 , 92 lp ........................................................................89 , 92 rc ................................................................ 89 , 90 , 92 xt ........................................................................89 , 92 oscillator selection ............................................................ 87 oscillator, wdt ................................................................. 99 oscillators capacitor selection ................................................... 90 crystal and ceramic resonators .............................. 89 rc ............................................................................. 90
pic16f872 ds30221c-page 160 ? 2006 microchip technology inc. p p bit stop bit (p) .............................................................. 52 packaging ............................................................... 151 ? 154 pcl register ..........................................................9 , 10 , 20 pclath register ......................................................... 9 , 20 pcon register .....................................................10 , 19 , 92 bor bit ...................................................................... 19 por bit ...................................................................... 19 pen bit stop condition enable bit (pen) ............................. 54 picdem 1 low cost picmicro demonstration board ............................................... 113 picdem 17 demonstration board ................................... 114 picdem 2 low cost pic16cxx demonstration board ............................................... 113 picdem 3 low cost pic16cxxx demonstration board ............................................... 114 picstart plus entry level development programmer ............................................................. 113 pie1 register .............................................................. 10 , 15 pie2 register .............................................................. 10 , 17 pinout descriptions ......................................................... 5 ? 6 pir1 register ............................................................... 9 , 16 pir2 register ............................................................... 9 , 18 pop ................................................................................... 20 por. see power-on reset porta ................................................................................ 5 associated registers ................................................. 30 functions ................................................................... 30 porta register ................................................... 9 , 29 ra3 ra0 and ra5 port pins ..................................... 29 trisa register .......................................................... 29 portb ................................................................................ 6 associated registers ................................................. 32 functions ................................................................... 32 portb register ................................................... 9 , 31 rb0/int pin, external ................................................ 98 rb7:rb4 interrupt-on-change .................................. 98 rb7:rb4 interrupt-on-change enable (rbie bit) ................................................... 98 rb7:rb4 interrupt-on-change flag (rbif bit) ............................................ 31 , 98 trisb register ................................................... 11 , 31 portc ................................................................................ 6 associated registers ................................................. 34 functions ................................................................... 34 portc register ................................................... 9 , 33 trisc register .......................................................... 33 power-down mode. see sleep power-on reset (por) .................................. 87 , 91 , 92 , 93 oscillator start-up timer (ost) .......................... 87 , 92 power control (pcon) register ................................ 92 power-down (pd bit) ................................................. 91 power-up timer (pwrt) .................................... 87 , 92 time-out (to bit) ....................................................... 91 time-out sequence on power-up .............................. 96 pr2 register .............................................................. 10 , 43 pro mate ii universal device programmer .................. 113 program counter reset conditions ..................................................... 93 program memory interrupt vector ............................................................ 7 paging ....................................................................... 20 program memory map and stack ................................ 7 reset vector ............................................................. 7 program verification ........................................................ 101 programming, device instructions .................................. 103 pulse width modulation. see capture/compare/pwm, pwm mode. push ................................................................................ 20 pwm mode setup ......................................................................... 49 r r/w bit .............................................................................. 59 read/write bit information (r/w) .............................. 52 r/w bit .............................................................................. 59 ra0/an0 pin ....................................................................... 5 ra1/an1 pin ....................................................................... 5 ra2/an2/v ref - pin ............................................................. 5 ra3/an3/v ref + pin ............................................................ 5 ra4/t0cki pin .................................................................... 5 ra5/ss /an4 pin ................................................................. 5 ram. see data memory rb0/int pin ........................................................................ 6 rb1 pin ............................................................................... 6 rb2 pin ............................................................................... 6 rb3/pgm pin ...................................................................... 6 rb4 pin ............................................................................... 6 rb5 pin ............................................................................... 6 rb6/pgc pin ...................................................................... 6 rb7/pgd pin ...................................................................... 6 rc0/t1oso/t1cki pin ....................................................... 6 rc1/t1osi pin .................................................................... 6 rc2/ccp1 pin .................................................................... 6 rc3/sck/scl pin ............................................................... 6 rc4/sdi/sda pin ................................................................ 6 rc5/sdo pin ...................................................................... 6 rc6 pin ............................................................................... 6 rc7 pin ............................................................................... 6 rcen bit receive enable bit (rcen) ...................................... 54 receive overflow indicator bit (sspov) .......................... 53 registers adcon0 (a/d control 0) register ............................ 79 adcon1 (a/d control 1) register ............................ 80 ccp1con (ccp control 1) register ........................ 45 eecon1 (eeprom control) register ...................... 24 intcon register ...................................................... 14 option_reg register ......................................13 , 36 pcon (power control) register ............................... 19 pie1 (peripheral interrupt enable 1) register ........... 15 pie2 (peripheral interrupt enable 2) register ........... 17 pir1 (peripheral interrupt request 1) register ........ 16 pir2 (peripheral interrupt request 2) register ........ 18 special function, summary ........................................ 9 sspcon (sync serial po rt control) register ........... 53 sspcon2 (sync serial port control 2) register ...... 54 sspstat (sync serial port status) register ........... 52 status register ...................................................... 12 t1con (timer1 control) register ............................. 39 t2con (timer 2 control) register ............................ 43
? 2006 microchip technology inc. ds30221c-page 161 pic16f872 reset ........................................................................ 87 , 91 reset conditions for all registers .......................... 93 reset conditions for pcon register ...................... 93 reset conditions for program counter ................... 93 reset conditions for special registers .................. 93 reset conditions for status register .................. 93 reset brown-out reset (bor). see brown-out reset (bor) mclr reset. see mclr power-on reset (por). see power-on reset (por) wdt reset. see watchdog timer (wdt) revision history ............................................................... 155 rsen bit repeated start condition enabled bit (rsen) ..... 54 s s bit start bit (s) ............................................................ 52 sample bit (smp) .............................................................. 52 sck pin ............................................................................. 55 scl pin .............................................................................. 58 sda pin ............................................................................. 58 sdi pin ............................................................................... 55 sdo pin ............................................................................. 55 sen bit start condition enabled bit (sen) ........................ 54 serial clock (sck) ............................................................. 55 serial clock (scl) ............................................................. 58 serial data address (sda) ................................................ 58 serial data in (sdi) ............................................................ 55 serial data out (sdo) ....................................................... 55 slave select (ss ) ............................................................... 55 sleep ................................................................87 , 91 , 100 smp bit .............................................................................. 52 software simulator (mplab sim) ................................... 112 special features of the cpu ............................................. 87 special function registers (sfrs) ...................................... 9 data eeprom and flash program memory .......... 23 speed, operating ................................................................. 1 spi clock edge select bit (cke) ....................................... 52 spi mode associated registers ................................................. 57 master mode .............................................................. 56 serial clock ............................................................... 55 serial data in ............................................................. 55 serial data out .......................................................... 55 slave select ............................................................... 55 spi clock ................................................................... 56 ss pin ................................................................................ 55 ssbuf register .................................................................. 9 mssp see also i 2 c mode and spi mode. sspadd register .............................................................. 10 sspbuf register ............................................................... 58 sspcon register ............................................................... 9 sspcon2 register ........................................................... 10 sspen bit ......................................................................... 53 sspif ......................................................................... 16 , 59 sspm3:sspm0 bits .......................................................... 53 sspov bit .................................................................. 53 , 59 sspov status flag ........................................................... 69 sspstat register ..................................................... 10 , 58 stack .................................................................................. 20 overflows ................................................................... 20 underflow .................................................................. 20 status register ..........................................................9 , 12 c bit .......................................................................... 12 dc bit ........................................................................ 12 irp bit ....................................................................... 12 pd bit ..................................................................12 , 91 rp1:rp0 bits ............................................................ 12 to bit ..................................................................12 , 91 z bit ........................................................................... 12 synchronous serial port enable bit (sspen) ................... 53 synchronous serial port interrupt ..................................... 16 synchronous serial port mode select bits (sspm3:sspm0) ...................................................... 53 t t1ckps0 bit ...................................................................... 39 t1ckps1 bit ...................................................................... 39 t1con register .................................................................. 9 t1oscen bit ..................................................................... 39 t1sync bit ....................................................................... 39 t2con register .................................................................. 9 time-out sequence ........................................................... 92 timer0 ............................................................................... 35 associated registers ................................................ 37 external clock ........................................................... 36 interrupt ..................................................................... 35 overflow flag (tmr0if bit) ...................................... 98 overflow interrupt ...................................................... 98 prescaler ................................................................... 36 t0cki ........................................................................ 36 timer1 ............................................................................... 39 associated registers ................................................ 42 asynchronous counter mode .................................... 41 counter operation ..................................................... 40 operation in timer mode .......................................... 40 oscillator ................................................................... 41 capacitor selection ........................................... 41 prescaler ................................................................... 41 reading and writing in asynchronous counter mode ........................................... 41 resetting of timer1 registers ................................... 41 resetting timer1 using a ccp trigger output ......... 41 synchronized counter mode ..................................... 40 timer2 ............................................................................... 43 associated registers ................................................ 44 output ....................................................................... 44 postscaler ................................................................. 43 prescaler ................................................................... 43 prescaler and postscaler .......................................... 44 timing diagrams a/d conversion ....................................................... 137 acknowledge sequence ............................................ 71 baud rate generator with clock arbitration ............. 65 brg reset due to sda collision during start condition ...................................... 75 brown-out reset ..................................................... 129 bus collision transmit and acknowledge ............................... 73 bus collision during a repeated start condition (case 1) .................................... 76 bus collision during a repeated start condition (case2) ..................................... 76 bus collision during a stop condition (case 1) .................................................... 77 bus collision during a stop condition (case 2) .................................................... 77
pic16f872 ds30221c-page 162 ? 2006 microchip technology inc. bus collision during start condition (scl = 0) ................................................... 75 bus collision during start condition (sda only) ................................................ 74 capture/compare/pwm .......................................... 131 clkout and i/o ..................................................... 128 external clock .......................................................... 127 first start bit timing .............................................. 65 i 2 c bus data ............................................................ 135 i 2 c bus start/stop bits ...................................... 134 i 2 c master mode transmission ................................. 68 i 2 c mode (7-bit reception) ................................. 60 , 70 i 2 c mode (7-bit transmission) ................................... 61 master mode transmit clock arbitration ................... 72 power-up timer ....................................................... 129 repeat start condition .......................................... 66 reset ..................................................................... 129 slave mode general call address sequence (7 or 10-bit mode) ...................................... 61 slow rise time (mclr tied to v dd via rc network) ........................................ 96 spi master mode ....................................................... 56 spi master mode (cke = 0, smp = 0) .................... 132 spi master mode (cke = 1, smp = 1) .................... 132 spi slave mode (cke = 0) ............................... 57 , 133 spi slave mode (cke = 1) ............................... 57 , 133 start-up timer .......................................................... 129 stop condition receive or transmit mode .............. 72 time-out sequence on power-up .............................. 96 time-out sequence on power-up (mclr not tied to v dd ) case 1 ............................................................... 95 case 2 ............................................................... 96 time-out sequence on power-up (mclr tied to v dd via rc network) ........ 95 timer0 ...................................................................... 130 timer1 ...................................................................... 130 wake-up from sleep via interrupt .......................... 101 watchdog timer ...................................................... 129 timing parameter symbology ......................................... 126 tmr0 register .............................................................. 9 , 11 tmr1cs bit ....................................................................... 39 tmr1h register .................................................................. 9 tmr1l register ................................................................... 9 tmr1on bit ....................................................................... 39 tmr2 register ..................................................................... 9 toutps3:toutps0 bits .................................................. 43 trisa register .................................................................. 10 trisb register .................................................................. 10 trisc register .................................................................. 10 u ua bit update address bit (ua) ........................................... 52 w wake-up from sleep ...............................................87 , 100 interrupts ................................................................... 93 mclr reset .............................................................. 93 wdt reset ................................................................ 93 wake-up using interrupts ............................................... 100 watchdog timer (wdt) ..............................................87 , 99 enable (wdte bit) .................................................... 99 postscaler. see postscaler, wdt programming considerations .................................... 99 rc oscillator ............................................................. 99 time-out period ......................................................... 99 wdt reset, normal operation ...........................91 , 93 wdt reset, sleep ............................................91 , 93 wdt reset, wake-up ............................................... 93 wcol ................................................................................ 65 wcol bit .......................................................................... 53 wcol status flag ........................................ 65 , 67 , 69 , 71 write collision detect bit (wcol) ..................................... 53 write verify data eeprom and flash program memory .......... 27 www, on-line support ...................................................... 2
? 2006 microchip technology inc. ds30221c-page 163 pic16f872 the microchip web site microchip provides online support via our www site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com, click on customer change notification and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com
pic16f872 ds30221c-page 164 advance information ? 2006 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds30221c pic16f872 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2006 microchip technology inc. ds30221c-page 165 pic16f872 pic16f872 product identification system to order or obtain information, e.g. , on pricing or delivery, refer to the factory or the listed sales office. part no. x /xx xxx pattern package temperature range device device pic16f87x (1) , pic16f87xt (2) ;v dd range 4.0v to 5.5v pic16lf87x (1) , pic16lf87xt (2 ) ;v dd range 2.0v to 5.5v temperature range blank = 0 c to +70 c (commercial) i= -40 c to +85 c (industrial) e= -40 c to +125 c (extended) package so = soic sp = skinny plastic dip ss = ssop examples: a) pic16f872 - i/p 301 = industrial temp., skinny pdip package, normal v dd limits, qtp pattern #301. b) pic16f872 - e/so = extended temp., soic package, normal v dd limits. c) pic16lf872 - /ss = commercial temp., ssop package, extended v dd limits. note 1: f=cmos flash lf = low power cmos flash 2: t = in tape and reel - soic, plcc, mqfp, tqfp packages only.
ds30221c-page 166 ? 2006 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta alpharetta, ga tel: 770-640-0034 fax: 770-640-0307 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway habour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - fuzhou tel: 86-591-8750-3506 fax: 86-591-8750-3521 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - shunde tel: 86-757-2839-5507 fax: 86-757-2839-5571 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xian tel: 86-29-8833-7250 fax: 86-29-8833-7256 asia/pacific india - bangalore tel: 91-80-4182-8400 fax: 91-80-4182-8422 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - gumi tel: 82-54-473-4301 fax: 82-54-473-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - penang tel: 60-4-646-8870 fax: 60-4-646-5086 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-572-9526 fax: 886-3-572-6459 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-3910 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 08/29/06


▲Up To Search▲   

 
Price & Availability of PIC16LF872-ISS

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X